integer pointer to constant integer
c++
Solution
cout << a << "\t" << *p << endl; //output: 10 11
You lied to the compiler and it got its revenge.
With:
const int a = 10;
you promised you'll never modify `a` object.
Problem
I'd like to know what is happening internally and its relation to values displayed. The code is: ``` # include <iostream> int main(){ using namespace std; const int a = 10; int* p = &a; //When compiling it generates warning "initialization from int* to //const int* discard const -- but no error is generated cout << &a <<"\t" << p <<endl; //output: 0x246ff08 0x246ff08 (same values) cout << a << "\t" << *p << endl; //output: 10 10 //Now.. *p = 11; cout << &a <<"\t" << p <<endl; //output: 0x246ff08 0x246ff08 (essentially, //same values and same as above, but..) cout << a << "\t" << *p << endl; //output: 10 11 return 0; } ``` QUESTION: If p = address-of-a, how come a=10, but *p = (goto address of a and read value in the memory location) = 11?