hello guys, i am new this form. i have a problem with the following program. the main aim of this program is to cahnge value of the const varibale using the pointer. this program is to just demonstrate that using is pointer we are allowed to change the const varaible.
code
#include<stdio.h>
int main()
{
const int c=10;
int *p;
p=(int *)&c;
*p=20;
printf("%d",c);
getchar();
}
saved as a .c extention
the result is success the const varibale is changes by 20
but when i save this as .cpp extention is cant see any change with the const variable can any one tell me is that:
here is the code which i wrote in cpp
#include<iostream.h>
int main()
{
const int c=10;
int *p;
p=(int *)&c;
*p=20;
cout<<<c;
}
can any one tell what is the problem here. why it is not changed in c++. and how is const variable is secures by changes the original value in the ,memory
thanks in advance