Hell "o" to all programmers out there.
I was just fiddling around with pointers to const
when i wrote this snippet.
int main (void)
{
int* ptr = NULL;
const int i = 20;
ptr = (int*) &i;
*ptr = 40;
printf ("\nThe addr of the const var is %p", &i);
printf ("\nThe addr in ptr is %p", ptr);
printf ("\nThe value of i is %d", i);
printf ("\nThe value of location pointed by ptr is %d", *ptr);
getchar ();
return 0;
}
THe problem i am facing is that the addr of the constant variable and that present in the pointer variable turns out to be the same but still when i modify the value using pointer to constant variable it raises no error. But when i try to query the value persent in the memory location pointed by the pointer and the value in the const variable it turns out to be different ???
How come the same memory location holds two different values?
Any suggestions or explanations would be gladly accepted.
Thanks to all in advance. Bye.