An interviewer writes int a[10]; int *p = a; and asks: "So a and p are the same, right?" Explain how arrays and pointers are similar and how they differ.
Show the explanation
No. They behave alike in many expressions, but they are different things.
What is the same
- In most expressions an array name decays to a pointer to its first element. So
p = ais legal, anda[i],*(a + i),p[i]and*(p + i)all mean the same element. - When you pass an array to a function, the function receives only a pointer.
void f(int a[])is exactlyvoid f(int *a).
What is different
int a[10]; | int *p = a; | |
|---|---|---|
| What it is | 10 ints stored together | one variable that holds an address |
sizeof | 10 * sizeof(int) (often 40) | size of a pointer (often 8 on 64-bit) |
| Can be reassigned? | No: a = something does not compile | Yes: p++ or p = other |
&x gives | int (*)[10], a pointer to the whole array | int ** |
Where decay does not happen: with sizeof a, with &a, and when a string literal initialises a char array.
The trap interviewers aim for: inside a function, sizeof(arr) / sizeof(arr[0]) does not give the length of the array that was passed in, because arr is only a pointer there. That is why C functions take the length as a separate parameter.
Original UniCircle question. Last reviewed 22 Oct 2026.
