Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/prolog/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual c++ 为什么这个VC++程序不编译?_Visual C++ - Fatal编程技术网

Visual c++ 为什么这个VC++程序不编译?

Visual c++ 为什么这个VC++程序不编译?,visual-c++,Visual C++,这是最近在一次课堂上提出来的。问题是if中首次出现ptr。错误是表达式必须是可修改的值 #include "stdafx.h" #include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { int * ptr = nullptr; int i = 7; if (ptr == nullptr && ptr = &i) c

这是最近在一次课堂上提出来的。问题是if中首次出现ptr。错误是表达式必须是可修改的值

#include "stdafx.h"
#include <iostream>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
    int * ptr = nullptr;
    int i = 7;
    if (ptr == nullptr && ptr = &i) 
        cout << *ptr;
    return 0;
}

括号是你的朋友。C/C++运算符优先级表很深,有些方面不直观

在本例中,逻辑AND&&绑定比赋值=。Binds==具有更高的优先级

当有疑问时,我总是使用google快速搜索c运算符优先表来获得一堆结果页面,所有这些页面都按照优先顺序提供了一个有用的表。事实上,在我自己的代码中有疑问时,我总是首先添加括号