Question 11
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
int value = 1;
const int *view = &value;
int *edit = &value;
*edit = 99;
printf("%d\n", *view);
return 0;
}
- A 99 Correct
- B 1
- C Compilation error
- D Undefined behaviour
Correct Answer: Option A
view and edit point to the same int. The const on view limits only what can be done through view; the object is not const, so writing through edit is perfectly legal.
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!