I have executed the below programm on both C and C++ compiler and got different results
#include <stdio.h>
int main()
{
const int a=10;
int *p=(int*)(&a);
*p = 20;
printf("address of a=%u\t%d\n", &a,a);
printf("address of p=%u\t%d\n", p,*p);
return 0;
}
With C compiler I got the output
address of a=1245052 20
address of p=1245052 20
With C++ compiler I got
address of a=1245052 10
address of p=1245052 20
Can anybody tell me why the different value for *p and a even thiough both are pointing to the same memory location?