Question:What will be output when you will execute following c code?#include<stdio.h>
void main(){
int a=5,b=10;
if(++a||++b)
printf("%d %d",a,b);
else
printf("John Terry");
}
Choose all that apply:
+ ExplanationConsider the following expression:
++a || ++b
In this expression || is Logical OR operator. Two important properties of this operator are:
Property 1:
(Expression1) || (Expression2)
|| operator returns 0 if and only if both expressions return a zero otherwise it || operator returns 1.
Property 2:
To optimize the execution time there is rule, Expression2 will only evaluate if and only if Expression1 return zero.
In this program initial value of a is 5. So ++a will be 6. Since ++a is returning a non-zero so ++b will not execute and if condition will be true and if clause will be executed.