Arrays in Functions & Decay in C
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.
Parameters are pointers
void f(int a[10]) ≡ void f(int *a) — identical signatures; the 10 documents intent the compiler ignores.
sizeof lies after decay
sizeof(a) inside f gives pointer bytes (8), not array bytes — compute lengths before the call and pass them along.
Multidim needs widths
void f(int m[][4]) pins 4 columns so row arithmetic works — mismatched widths fail to compile.
Decay means direct access
The callee modifies caller memory in place — efficient, and the reason const exists for read-only array params.
#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;}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in C yourself — building beats watching.