2026-08-20
decay.c
#include <stdio.h>
void describe(int arr[10]) {
printf("%zu\n", sizeof(arr));
}
int main(void) {
int nums[10] = {0};
printf("%zu\n", sizeof(nums));
describe(nums);
}
What do the two printed values have in common — or not?
Answer
They differ. In main, nums is an actual array, so sizeof(nums) is 10 * sizeof(int) (usually 40). But a function parameter written as int arr[10] is silently adjusted by the compiler to int *arr — arrays decay to pointers when passed to functions. So sizeof(arr) inside describe is just sizeof(int*) (usually 8), not 40. Well-defined by the standard, just easy to forget.