C++ cout后接地址和指针间接引用的值的区别:
cout接地址,以
#include <iostream>
using namespace std;
void main()
{
"cout后面接地址:" << endl;
char str[] = "C Language", *p = str;
cout << p << endl;
cout << p + 2 << endl;
cout << &str[7] << endl;//这里cout后面跟地是地址所以用&
while (*p != '\0')
cout << p++ << endl;
cout << "cout后面接指针间接引用的值:" << endl;
p = str;//这里必须得重新让指针指向str
while (*p != '\0')
cout << *p++;
}
为例:当cout后接地址,则输出的是该地址起到字符串数组结尾的值,当cout后接指针间接引用的值,输出的只是该指针所指地址的值(*p的值)