const in C and C++
By chys on May 31st, 2010
The const keyword has “constant” and “read-only variable” semantics in C++, but only “read-only variable” semantics in C.
To illustrate this difference, try compiling the following code:
const int x = 2; int y[x];
This is not legal C, because x is not a compile-time constant semantically.
But it is legal C++, because const also has constant semantics and thus x is a compile-time constant.
Related posts:
Tags: C/C++
Leave a Reply
Hint: Register at Gravatar and your comments will be accompanied by your personalized icon.
