Question 6
Back to Exercise
What is the result of *(int *) &limit = 20; when limit was defined as static const int limit = 10;?
- A limit becomes 20
- B Undefined behaviour – the object may be in read-only memory or its value folded into the code Correct
- C A compile error
- D limit becomes 0
Correct Answer: Option B
The cast removes the compiler's protection, but the object is still const. Writing to it is undefined: on most systems it sits in read-only memory and the program crashes.
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!