C Output Prediction Medium +20 XP
Array Decay
What does sizeof print for the pointer?
CRead-only
int arr[10];
int *p = arr;
printf("%zu %zu", sizeof(arr), sizeof(p));What is the output?
Show answer and explanation
Answer: 40 8
sizeof(arr) = 10 ints × 4 bytes = 40. sizeof(p) is the pointer size = 8 on 64-bit systems. Array decays to pointer when assigned.
Hint: Array and pointer are different sizes.
What this challenge tests
Output Prediction in C: arrays, pointers, sizeof.