question for C++ constant# Programming - 葵花宝典
n*d
1 楼
Can anybody explain it?
ip=0x22cce4 &k=0x22cce4
*ip=5
ip=0x22cce4 &k=0x22cce4
*ip=6
k=5
#include
using namespace std;
int main() {
const int k = 5;
long k_add = (long)&k;
int *ip = (int *)k_add;
cout << "ip=" << ip << " &k=" << &k << endl;
cout << "*ip=" << *ip << endl;
*ip = 6;
cout << "ip=" << ip << " &k=" << &k << endl;
cout << "*ip=" << *ip << endl;
cout << "k=" << k << endl;
}
ip=0x22cce4 &k=0x22cce4
*ip=5
ip=0x22cce4 &k=0x22cce4
*ip=6
k=5
#include
using namespace std;
int main() {
const int k = 5;
long k_add = (long)&k;
int *ip = (int *)k_add;
cout << "ip=" << ip << " &k=" << &k << endl;
cout << "*ip=" << *ip << endl;
*ip = 6;
cout << "ip=" << ip << " &k=" << &k << endl;
cout << "*ip=" << *ip << endl;
cout << "k=" << k << endl;
}