i have a question about constant variable in c/c++.The following is my code:
Code:
int main()
{
const int a = 10;
int * p = (int*)&a;
*p = 11;
printf("the address of p = %p\n",p);
printf("the address of a = %p\n",&a);
printf("value of a = %d\n",a);
printf("value of *p = %d\n",*p);
return 0;
}
And the output is :
Code:
the address of p = 0xbfecca1c
the address of a = 0xbfecca1c
value of a = 10
value of *p = 11
I don't know why variable "a" and "p" have the same address but their value are different?