Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.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
C++ 在同一行c+;中相同变量上,此代码后缀和前缀的输出背后的逻辑是什么+;_C++_Operator Precedence_Prefix - Fatal编程技术网

C++ 在同一行c+;中相同变量上,此代码后缀和前缀的输出背后的逻辑是什么+;

C++ 在同一行c+;中相同变量上,此代码后缀和前缀的输出背后的逻辑是什么+;,c++,operator-precedence,prefix,C++,Operator Precedence,Prefix,如何为后增量(a++)返回5。根据运算符优先级,a++应首先执行,并应返回4 #include <iostream> using namespace std; int main() { int a=4,b=4; cout<<++b<<" "<<b++<<" "<<a++<<" "<<++a<<endl; return 0; } Output: 6 4 5 6 #包

如何为后增量(a++)返回5。根据运算符优先级,a++应首先执行,并应返回4

#include <iostream>
using namespace std;
int main()
{
    int a=4,b=4;
    cout<<++b<<" "<<b++<<" "<<a++<<" "<<++a<<endl;
    return 0;
}
Output: 6 4 5 6
#包括
使用名称空间std;
int main()
{
INTA=4,b=4;

cout编译代码时应始终启用警告。编译器将告诉您结果可能未定义:

prog.cc: In function 'int main()':
prog.cc:6:22: warning: operation on 'b' may be undefined [-Wsequence-point]
     cout<<++b<<" "<<b++<<" "<<a++<<" "<<++a<<endl;
                     ~^~
prog.cc:6:41: warning: operation on 'a' may be undefined [-Wsequence-point]
     cout<<++b<<" "<<b++<<" "<<a++<<" "<<++a<<endl;
                                         ^~~
prog.cc:在函数“int main()”中:
程序cc:6:22:警告:“b”上的操作可能未定义[-Wsequence point]

在C++中,你可以编译为哪个版本的iCR?流中的评价顺序不能保证。即<代码> A++<代码>可以在代码> > +A<代码>之后进行评估。唯一的保证是结果按一定顺序显示。你应该看看@克里斯C++ 11。我得到的顺序是未定义的。谢谢。ng启用和链接。我得到了答案。