小编max*_*axE的帖子

指针:初始化与声明

我是一个C++菜鸟,我很确定这是一个愚蠢的问题,但我不太明白为什么从以下代码出现错误(不会出现):

#include <iostream>
using namespace std;


int main() 
{
int a,*test; 

*test = &a;  // this error is clear to me, since an address cannot be 
             // asigned to an integer  


*(test = &a); // this works, which is also clear
return 0;
}
Run Code Online (Sandbox Code Playgroud)

但为什么这也有效呢?

#include <iostream>
using namespace std;

int main() 
{
int a, *test= &a;  // Why no error here?, is this to be read as:
                   // *(test=&a),too? If this is the case, why is the 
                   // priority …
Run Code Online (Sandbox Code Playgroud)

c++ pointers c++14

17
推荐指数
1
解决办法
1026
查看次数

标签 统计

c++ ×1

c++14 ×1

pointers ×1