Just tried Mukesh's code inside VS2010 C++ project:
int _tmain(int argc, _TCHAR* argv[])
{
const int x = 5;
int *p = (int *) &x;
printf("x = %d\n", x);
*p = 10;
printf("x = %d", x);
return 0;
}
And guess what? Running the console application yields:
x = 5
x = 5
Debugging the application step by step shows x having a value of 10 in the variable view, but the output is the same as above:
x = 5
x = 5
Now that's strange. Some how the pointer stuff does not work in C++, when x is declared as const int.
Cheers,
Manfred