Visual c++ 为什么这个VC++程序不编译?
这是最近在一次课堂上提出来的。问题是if中首次出现ptr。错误是表达式必须是可修改的值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
#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运算符优先表来获得一堆结果页面,所有这些页面都按照优先顺序提供了一个有用的表。事实上,在我自己的代码中有疑问时,我总是首先添加括号