我不明白为什么我不能打印指针的地址.我知道理解指针是非常基础的,所以任何帮助都会受到赞赏.
void printp(int& test)
{
cout << test << endl;
}
int main()
{
int *p = new int;
*p = 1;
int np = 0;
// printp(p); // why doesn't this print the address of p?
// printp(&p); // why doesn't this print the address of p?
printp(*p); // prints 1
printp(np); // prints 0
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用'printp(p)'时出现以下错误.
test.cpp: In function ‘int main()’:
test.cpp:17:10: error: invalid conversion from ‘int*’ to ‘int’ [-fpermissive]
printp(p); // why doesn't this print …Run Code Online (Sandbox Code Playgroud)