Monday, 14 May 2012

Can a variable become both constant and volatile?

 Yes. The const modifier implies that this particular program code cannot change the value of the actual variable, but that will not imply that the value cannot be changed by means outside this code.
For instance, within the example in frequently asked questions, the timer structure was accessed through a volatile const pointer. The function by itself did not change the value of the timer, so it had been declared const. However, the value had been changed by hardware on the computer, so it was declared volatile. If a variable is both equally const and volatile, the two modifiers can come in either order.

No comments:

Post a Comment