|
最近学习c++的指针,被折磨死了。。。
char str[] = "helloworld";
char *pstr = &str[0];
cout << pstr << endl;
int i[] = { 1, 2, 3, 4, 5 };
int *pi = &i[0];
cout << pi << endl;
这段代码中的pstr和pi一个是字符型指针一个是整形指针,为什么一个得出helloworld,一个得出004FFA50?不是都应该得出地址吗?
C++用cout时,后面跟的指针类型为char *或者字符串名称,默认输出存储内容,用(int *)强制转换 ;cout << (int * )pstr << endl ;
|
上一篇: pid 输出问题下一篇: 关于指针的问题
|