int main() {
const int i =10;
int *j = const_cast<int*>(&i);
cout<<endl<<"address of i "<<&i;
cout<<endl<<"value of j "<<j;
(*j)++;
cout<<endl<<"value of *j "<<*j;
cout<<endl<<"value of i "<<i;
// If Not use Const //
int k = 10;
int *p = &k;
cout<<endl<<"address of k "<<&i;
cout<<endl<<"address of p "<<&p;
(*p)++;
cout<<endl<<"value of *p "<<*p;
cout<<endl<<"value of k "<<k<<endl;
}
Output is :
address of
i0xbf8267d0
value ofj0xbf8267d0
value of*j11
value ofi10
address ofk0xbf8267d0
address ofp0xbf8267c8
value of*p11
value ofk11
Can someone please explain why at the 3rd and 4th line of output
*j is 11 and i is 10.
Why is i also not 11?