I'm taking an entry level C++ course based on 'Thinking in C++. Forgive me for perhaps missing the obvious:
#include <iostream> // cout
using namespace std;
int main(){
const int i = 0;
int* j;
j = const_cast<int*>(&i);
*j = 5;
cout << (&i) << "," << i << "," << j << "," << (*j) << endl;
system("pause");
}
My system returns:
'0x22ff74,0,0x22ff74,5'
I only declared two variables, one containing an int and one containing a pointer to that same int. I thought const_cast was to 'convert from a const to a nonconst'. So how is cout finding three distinct values?