霍邱县河口镇:C++问题,这个程序会输出什么?

来源:百度文库 编辑:神马品牌网 时间:2024/03/29 19:44:54
#include <iostream.h>

int main()
{
int intvar = 10;
int *intptr;
intptr = &intvar;

cout << "\nLocation of intvar: " << &intvar;
cout << "\nContents of intvar: " << intvar;
cout << "\nLocation of intptr: " << &intptr;
cout << "\nContents of intptr: " << intptr;
cout << "\nThe value that intptr points to: " << *intptr;

return 0;
}

Location of intvar: xxxxxxxx
Contents of intvar: 10
Location of intptr: yyyyyyyy
Contents of intptr: xxxxxxxx
The value that intptr points to: 10

第一行xxxxxxx是不确定的数,他是intvar在内存中的地址,每次编译运行时,系统分配给它的地址都不确定

第二行是intvar中保存的值,即10

第三行yyyyyyyy是不确定的数,解释同第一行

第四行xxxxxxxx是不确定的数,解释同上,但在这里它等于第一行的输出,因为intptr中存储的是intvar在内存中的地址

第五行引用了intptr指向的对象(也就是intvar)中保存的值,即10