C++ 逻辑运算符

C++ 逻辑运算符

尝试下面的示例来了解C++中可用的所有逻辑运算符。

复制并粘贴下面的C++程序到test.cpp文件中,编译并运行该程序。

#include <iostream>
using namespace std;

main() {
   int a = 5;
   int b = 20;
   int c ;

   if(a && b) {
      cout << "Line 1 - Condition is true"<< endl ;
   }

   if(a || b) {
      cout << "Line 2 - Condition is true"<< endl ;
   }

   /* Let's change the values of  a and b */
   a = 0;
   b = 10;

   if(a && b) {
      cout << "Line 3 - Condition is true"<< endl ;
   } else {
      cout << "Line 4 - Condition is not true"<< endl ;
   }

   if(!(a && b)) {
      cout << "Line 5 - Condition is true"<< endl ;
   }

   return 0;
}

当上述代码被编译和执行时,它产生以下结果 –

Line 1 - Condition is true
Line 2 - Condition is true
Line 4 - Condition is not true
Line 5 - Condition is true

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程