有关int *,const int* 等
代码如下:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
const int iNum = 0x1024;
int *pNum = (int*)&iNum;
*pNum = 3;
// const int * const pNum = &iNum;
// const int * const & pNum = &iNum;
cout<<"iNum: "<<hex<<"Add: "<<&iNum<<" Value: "<<iNum<<endl
<<"*pNum: "<<hex<<"Add: "<<pNum<<" Value: "<<*pNum<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
以上程序在Dev-C++ 4.9.9.2上测试通过,输出结果如下:
iNum: Add: 0x22ff74 Value: 1024
*pNum: Add: 0x22ff74 Value: 3
现有以下问题请教:
1。 const int * const & pNum = &iNum;此句不理解
2。输出结果中显示:pNum与&iNum相同,但为什么值不同呢?
3。// const int * const pNum = &iNum;
// const int * const & pNum = &iNum;
这两句有什么区别呢?有什么实用性呢?
还有其它问题,不知道怎么表达,总之觉得此程序有些怪怪的.
请指教,谢谢!