I wrote a program like this(test.cpp)
and the result is
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~
pointer to a =2
const a =1
address of a 0xbfffdd44
address of p 0xbfffdd44
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~
what on earth the value is in (0xbfffdd44)? Thank you
#include <iostream>
using namespace std;
int main()
{
const int a = 1;
int* p;
p = (int*)&a;
(*p)++;
cout<< "pointer to a ="<<*p<<endl ;
cout<< "const a =" << a<< endl;
cout<< "address of a" <<&a<<endl;
cout<< "address of p" <<p<<endl;
return 0;
}
and the result is
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~
pointer to a =2
const a =1
address of a 0xbfffdd44
address of p 0xbfffdd44
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~
what on earth the value is in (0xbfffdd44)? Thank you
#include <iostream>
using namespace std;
int main()
{
const int a = 1;
int* p;
p = (int*)&a;
(*p)++;
cout<< "pointer to a ="<<*p<<endl ;
cout<< "const a =" << a<< endl;
cout<< "address of a" <<&a<<endl;
cout<< "address of p" <<p<<endl;
return 0;
}
Comment