【发布时间】:2011-09-20 10:11:12
【问题描述】:
当我编译并运行这个 C++ 代码时,我没有得到预期的输出。
#include <iostream>
using namespace std;
int main()
{
int * i = new int;
long * l = new long;
char * c = new char[100];
float * f = new float[100];
cout << "i " << i << endl;
cout << "l " << l << endl;
cout << "c " << c << endl;
cout << "f " << f << endl;
delete i;
delete l;
delete []c;
delete []f;
cin.get();
return 0;
}
在 unix 机器上我得到
i 0x967f008
l 0x967f018
c
f 0x967f090
在 Windows 机器上,c 的值打印为一行随机字符。
请有人解释为什么它没有正确打印 char 数组的指针。
谢谢
【问题讨论】: