What values will be printed if you remove the volatile keyword in the following code:
1: volatile const int a = 10;
2: int *ptr = (int *) &a;
3: *ptr = 1000;
4: cout << a << endl;
5: cout << *ptr << endl;
Explanation
The values 10 and 1000 will be displayed. If the volatile keyword is absent the compiler will perform optimization. In this case, instead of the variable a in the line 5, the corresponding constant will be used.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
C++ quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes