Quiz Entry - updated: 2026.07.10
What's the difference between int *p and int p[] as function parameters?
They're identical — a parameter written int p[] decays to int *p, so the function only ever receives a pointer and loses the array's size.
// These function signatures are EXACTLY the same:
void foo(int *arr);
void foo(int arr[]);
// The 10 is ignored!
void foo(int arr[10]);
Inside the function:
void foo(int arr[]) {
// Returns sizeof(int*), NOT array size!
sizeof(arr);
// arr is just a pointer, array size information is lost
}
That's why you need to pass the size separately:
void process(int *arr, size_t len) {
for (size_t i = 0; i < len; i++) {
arr[i] *= 2;
}
}
int main() {
int data[] = {1, 2, 3, 4, 5};
process(data, sizeof(data) / sizeof(data[0]));
}
Exception - pointers to arrays preserve size:
// Pointer to array of 10 ints
void foo(int (*arr)[10]) {
// 40 bytes! Size preserved
sizeof(*arr);
}