Difficulty: Easy
Correct Answer: 65536
Explanation:
Introduction / Context:
This problem checks if you can compute the size argument passed to malloc and interpret it as bytes reserved, independent of the pointer's base type. The cast to int does not change the number of bytes requested.
Given Data / Assumptions:
Concept / Approach:
malloc receives a size in bytes. The expression 256 * 256 equals 65536, so malloc attempts to reserve exactly 65536 bytes. The type of p (int) only affects how you interpret the memory later, not the number of bytes allocated.
Step-by-Step Solution:
Verification / Alternative check:
To reserve space for N ints portably, use malloc(N * sizeof *p). Here the code requests a raw byte count; counting bytes confirms the value 65536.
Why Other Options Are Wrong:
Common Pitfalls:
Confusing number of elements with number of bytes or assuming sizeof(int) is implicitly applied. Always multiply by sizeof when allocating typed arrays.
Final Answer:
65536
Discussion & Comments