constants in C/C++

Hi all
My question is related to following sample code which tries to change consant value by pointers.(I know it is wrong practice but i am surprised by mis-behaviour)
The code:

#include <stdio.h>

int main()
{
const int x = 10;
int *y;
const int * const z = &x;

y = (int *)&x;
*y=11;
printf('%p %d ', y, *y);
printf('%p %d ', &x, x);
printf('%p %d ', z, *z);
return 0;
}

The output:

0012FF7C 11
0012FF7C 10
0012FF7C 11

The above output is when the program was compiled as cpp file and got
11
11
11
when compiled as "c" file.
Also
const int x=10;
int arr[x];
works with c++ compiler and not C.

My question is why is this mis-behaviour.

Actually, you are misbehaving, not the compiler. When you violate the rules of a language any behavior by the compiler becomes legal. As for why this particular result happens, code like:
const int x = 10;
printf("%p %d \n", &x, x);

can be rewritten by the compiler as something like:
const int x = 10;
printf("%p 10 \n", &x);

Whether or not this happens is up the compiler. Most compilers have options to control optimizations. By fiddling with these options you may be able to induce both behaviors from both compilers. Or maybe not. "Garbage in, garbage out" applys heavily to compilers.

I agree that compilers are free to optimise the way they like.But i was surprised to see exactly similar behaviour for c and c++ respectively on VC++ ,Turbo,gnu,aCC compilers.
All changed value of constant in C compilation but the value remained same in C++ compilation.

similarly for array index being declared with constant.

Why all the vendors opted for such behaviour made me suspect if their is some standard.

shobhit