大佬教程收集整理的这篇文章主要介绍了条件中的多个表达式(C/C++),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
#include <iostream> #include <cstdlib> int main(){ ///BUT THIS DOES NOT WORK! if ( (2 + 2) == (1 + 3) == (4 + 0) ){ std::cout << "not executed" << std::endl; } return EXIT_succesS; }@H_419_12@假设这些数字实际上是变量.这就是我要做的事情:
#include <iostream> #include <cstdlib> int main(){ int n1 = 2; int n2 = 2; int n3 = 1; int n4 = 3; int n5 = 4; int n6 = 0; int a = n1 + n2; ///this works if ( (n3 + n4) == a && (n5 + n6) == a){ std::cout << "executed!" << std::endl; } return EXIT_succesS; }@H_419_12@问题:为什么我的第一个例子不起作用?
我可以像这样为多个变量分配相同的值:
#include <iostream> #include <cstdlib> int main(){ int a,b,c,d; a=b=c=d=9; ///prints: 9999 std::cout <<a<<b<<c<<d<<'\n'; return EXIT_succesS; }@H_419_12@
以上是大佬教程为你收集整理的条件中的多个表达式(C/C++)全部内容,希望文章能够帮你解决条件中的多个表达式(C/C++)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。