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
}
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
}
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