Learn C
#include "arraysstrings/array_params.h"

Arrays in Functions & Decay in C

#concept

Array parameters are lies C tells politely: void f(int a[10]) really receives int *a — the size is ignored (except in rare static-annotated forms), the array decays to a pointer, and sizeof inside reports pointer size, not array size. Consequences: pass lengths explicitly, and never compute array size inside the callee.

Multidimensional parameters must declare all but the first dimension (void f(int m[][4])), and strings-as-char* follow the same decay. The decay rule has exactly one upside: zero-cost passing with no copying — the callee works on the caller's storage directly.

#how it works
1

Parameters are pointers

void f(int a[10]) ≡ void f(int *a) — identical signatures; the 10 documents intent the compiler ignores.

2

sizeof lies after decay

sizeof(a) inside f gives pointer bytes (8), not array bytes — compute lengths before the call and pass them along.

3

Multidim needs widths

void f(int m[][4]) pins 4 columns so row arithmetic works — mismatched widths fail to compile.

4

Decay means direct access

The callee modifies caller memory in place — efficient, and the reason const exists for read-only array params.

#example
#include <stdio.h>
 
void show(int *a, int n) {
for (int i = 0; i < n; ++i)
printf("%d ", a[i]);
printf("\n");
}
 
int main(void) {
int vals[] = {5, 6, 7};
show(vals, 3);
return 0;
}
Output
5 6 7
1vals deduces int[3]; passing it decays to a pointer — show receives an address plus the explicit length 3.
2Indexing the pointer walks the caller's storage directly, printing 5 6 7 with no copy made.
3Had show tried sizeof(a)/sizeof(a[0]), it would print pointer-size math — the length parameter is what saves it.
#use cases
Array-processing functions taking (pointer, length) pairs
const-qualified array params documenting read-only access
Multidimensional processing with pinned-width signatures
Recognizing decay at every array/function boundary in reviews

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in C yourself — building beats watching.