Flipkart.com

II.7: Can a variable be both const and volatile?

Answer:
Yes. The const modifier means that this code cannot change the value of the variable, but that does not mean that the value cannot be changed by means outside this code. For instance, in the example in II.6, the timer structure was accessed through a volatile const pointer. The function itself did not change the value of the timer, so it was declared const. However, the value was changed by hardware on the computer, so it was declared volatile. If a variable is both const and volatile, the two modifiers can appear in either order.
Reference:
II.6: When should the volatile modifier be used?
II.8: When should the const modifier be used?
II.14: When should a type cast not be used?

No comments:

Post a Comment