Question 10
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
int n = 7;
int v[n];
n = 100; /* does this change v? */
printf("%zu\n", sizeof v);
return 0;
}
- A 400
- B 8
- C Compilation error
- D 28 Correct
Correct Answer: Option D
For a VLA, sizeof is worked out at run time from the size the array had when it was created: 7 × 4 = 28. Changing n afterwards does not resize v.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!