0
#include <iostream>
#include<string>
using namespace std;

int main() {
    int a=30,b=1, c=5, i=10;
    i=b<a<c;
    cout<<i<<endl;
    
    return 0;
}

Hello I have question about this code. when I run the code, I get the result which is 1, but I am not sure the relationship about i=b<a<c; and why I get the result

Thank you.

Sho
  • 25
  • 4

1 Answers1

0

int a=30,b=1, c=5, i=10; i=b<a<c;

i=b<a<c

is interpreted as:

  1. compute (b<a)
  2. compare the result to see if it is < c
  3. place that result into the variable i

So this is what happens:

  1. b<a is evaluated as 1<30, which is true, so the result is 1 .
  2. next this 1 result is compared to c, which is evaluated as 1< 5, which is also true, so that result is also 1
  3. this final 1 result is set as the value in the variable i.
Matt Miguel
  • 1,325
  • 3
  • 6