0

I was just checking on this code and testing the working of relational operators in depth, i thought at first the b variable would be -1 in the output but later found out it was 0 , i figured it was implemented in such a way that as soon as one true condition is found the other parts(operands) of OR(||) operator are skipped , Just wondering if anyone has the source code or any clue how the || operator was coded to do this skipping, I know of operator overloading i want to add this small plus point to my overloaded operators as well.

#include<iostream>

int main()
{
    int a = 1;
    int b = 1;
    int c = a || --b;
    int d = a-- && --b;
    std::cout << "a = " << a << " b = " << b << " c = " << c << " d = " << d << std::endl;
    return EXIT_SUCCESS;
}
RNGesus.exe
  • 205
  • 1
  • 12
  • 1
    "*as one false condition is found the other parts of OR(||) operator are skipped*" You have "OR" confused with "AND". – Nicol Bolas May 08 '20 at 17:50
  • [`EXIT_SUCCESS`](https://en.cppreference.com/w/cpp/utility/program/EXIT_status) is from `#include `. – Eljay May 08 '20 at 18:03
  • `b` does not get decremented here: `int c = a || --b;` [https://ideone.com/RntvQJ](https://ideone.com/RntvQJ) – drescherjm May 08 '20 at 18:15

0 Answers0