在刚开始学习C/C++过程中,我们希望输出各个变量的地址来窥探一些我们“百思不得其解”的现象,例如搞清函数堆栈相关的程序内部秘密。
先看下面示例:
#include<stdio.h>
#include<iostream>
using namespace std;
class TestArrange
{
public:
long m_lng;
char m_ch1;
TestArrange()
{
m_lng = 0;
m_ch1 = 'a';
m_int = 0;
m_ch2 = 'a';
}
const int* GetIntAddr()
{
return &m_int;
}
const char* GetChar2Addr()
{
return &m_ch2;
}
private:
int m_int;
char m_ch2;
};
int main(void)
{
TestArrange test;
cout << "对象的地址:" << &test << endl;
cout << "m_lng地址:" << &(test.m_lng) << endl;
cout << "m_ch1地址:" << &(test.m_ch1) << endl;
cout << "m_int地址:" << test.GetIntAddr() << endl;
cout << "m