Difficulty: Medium
Correct Answer: 2, 8
Explanation:
Introduction / Context:
This question evaluates understanding of pointers to arrays and the difference between the size of a pointer and the size of the pointed-to object. The result depends on platform pointer size and known array dimensions.
Given Data / Assumptions:
Concept / Approach:
sizeof(p) is the size of the pointer itself (near pointer, 2 bytes). sizeof(*p) is the size of the array it points to, which is 4 * sizeof(int) = 4 * 2 = 8 bytes. The malloc line allocates MAXROW arrays of 4 ints, but the printf only asks for the two sizes.
Step-by-Step Solution:
Verification / Alternative check:
On 32-bit systems, the first value would typically be 4, and on 64-bit systems 8, confirming platform dependence for pointer size only.
Why Other Options Are Wrong:
Common Pitfalls:
Confusing sizeof(p) with the size of allocated memory or forgetting that *p is an entire array, not a single int.
Final Answer:
2, 8
Discussion & Comments