Cpp - What is the output: logic operator?

Question

The int variable x contains the number 7.

Calculate the value of the following logical expressions:

a.  x < 10 && x >= -1 
b.  !x && x >= 3 
c.  x++ == 8 || x == 7 


Click to view the answer

a.   true 
b.   false 
c.   false

Demo

#include <iostream> 
using namespace std;
int main()// w w  w  .ja v  a  2s  . c  o m
{
  int x = 7;
  bool b = x < 10 && x >= -1;
  cout << b << endl;

  b = !x && x >= 3;
  cout << b << endl;

  b = x++ == 8 || x == 7;
  cout << b << endl;
  return 0;
}

Result

Related Exercise