I found this in the algogeeks forum. Can anyone explain how value of i
is still 0
, but *p
shows 2
although their addresses are the same.
#include<stdio.h>
int main()
{
const int i = 0;
int * p ;
p = (int *) & i;
*p = 2;
printf("(i,p): %x %x \n",&i,p);
printf("(i,p): %d %d \n",i,*p);
}
The output of the program is:
(i,p): bfdf6234 bfdf6234
(i,p): 0 2