-2

In the following code why does the value of j remains zero even after the statement j=i+10.

#include <stdio.h>
int main()
{
 int i = 10, j = 0;
 if (i || (j=i+10))
   printf("%d",j);// j=0
}
Hrishi
  • 1
  • 1

1 Answers1

4

Why does value of j not change? Because i is non-zero and logical OR (||) properties is that if 1st operand is true don't check 2nd operand.

if ( i    ||  (j=i+10))
     |           |             
    10(True)   not evaluated
Achal
  • 11,821
  • 2
  • 15
  • 37