What does the following code do? int* ptr = (int*)malloc(100 * sizeof(int));

What does the following code do?
int* ptr = (int*)malloc(100 * sizeof(int));
A. Static Memory Allocation
B. Static Memory Clearance
C. Dynamic Memory Allocation
D. Dynamic Memory Clearance
 
Answer: C
Explanation: The sizeof() function here is being used to allocate a block of memory. This code is dynamic because the size of int is different on different machine architectures. So, we have allocated a block of memory that is enough to hold 100 integers irrespective of the size of the int data type in the machine in which this code is going to be executed.
 

Tìm kiếm

Back
Top