Which of the following statements is an example of dynamic memory allocation ?
- AOption (a)
int k = 20;
- BOption (b)
struct S { … }s;
- COption (c)
float *p = (float *) malloc (10 * sizeof (float)) ;
- DOption (d)
int x = 10, *p = &x;
View answer & explanationHide answer & explanation
Correct answer
float *p = (float *) malloc (10 * sizeof (float)) ;
Why this answer is correct
The correct answer is **option 3) float p = (float ) malloc (10 * sizeof (float));
Key Points
- Dynamic memory allocation means allocating memory during runtime using functions like:
- malloc()
- calloc()
- realloc()
- free() (for deallocation)
- Option 3: float *p = (float *) malloc(10 * sizeof(float));
✅ This allocates memory for 10 floats at runtime → dynamic allocation
Other Options:
- Option 1: int k = 20; → static allocation on the stack ❌
- Option 2: struct S {…} s; → structure variable statically allocated ❌
- Option 4: int x = 10, p = &x; → pointer pointing to statically allo
