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
i
0xbf8267d0
value ofj
0xbf8267d0
value of*j
11
value ofi
10
address ofk
0xbf8267d0
address ofp
0xbf8267c8
value of*p
11
value ofk
11
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?