Difficulty: Easy
Correct Answer: 24 bytes
Explanation:
Introduction / Context:
This problem tests computing total bytes allocated when using a pointer to an array type with malloc. It reinforces that sizeof(*p) represents the entire array object, not just a single element.
Given Data / Assumptions:
Concept / Approach:
sizeof(*p) = number_of_columns * sizeof(int) = 4 * 2 = 8 bytes. The malloc call requests MAXROW * sizeof(*p) = 3 * 8 = 24 bytes. The pointer type or casting does not change the size requested.
Step-by-Step Solution:
Verification / Alternative check:
Printing sizeof(*p) in code (as in the previous question) yields 8, confirming the per-row size. Multiplying by 3 confirms 24.
Why Other Options Are Wrong:
Common Pitfalls:
Forgetting that *p is an entire array type and miscounting bytes by element instead of by row.
Final Answer:
24 bytes
Discussion & Comments