In most expressions, an array name is implicitly converted ("decays") to a pointer to its first element. The critical consequence is at function calls: when you pass arr to a function, the function receives only a pointer, the array's size is not transmitted. Even if you write the parameter as int a[10], the compiler rewrites it to int *a, and sizeof(a) inside the function returns the pointer size (e.g. 8), not the array's byte count. That's why sizeof(arr)/sizeof(arr[0]) to compute length works only in the scope where arr is a real array, and why every C function taking an array must also take a separate length parameter. You simply cannot recover the size after decay.
C Programming · Interview question
What is array-to-pointer decay, and why does it matter when passing arrays to functions?
A strong answer
What a weak answer sounds like
You know the answer. Do you know what gets you dinged?
Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.
From the lesson
Pointer Arithmetic & Arrays
Why arr[i] is literally *(arr + i), how pointer math scales by type size, and the array-to-pointer decay that loses your size the moment you call a function.