29. What will be the output:
int a=2;
if (a=0)
printf("a is non zero");
elseif(a>0)
printf("a is +ve");
else
printf("a is zero");
it will not give compilation error, the if condition is proper,
it will be executed as like value "0" will be assigned to a and then it will check the if condition.
basically when we put any condition in if condition it check 0/1 like if (p==5) if p value is 5 then for this condition it will be something like if(1) in other scenario like if p is not equal to 5 then statement will be like if(0).
Such thing is happening in the given partial code, the last statement will be like if (0), which is false and control will go to else part. so that answer will be a is zero. However if you put a=5 then it will print a i non zero.
Sandeep Verma
23 Aug, 2018 5:03 PM
It will give a compile time error due to first if condition.
Given : if(a=0)
It should be : if(a==0)
Report Error
Report Error
Please Login First Click Here
Subham
23 Aug, 2018 5:09 PM
it will not give compilation error, the if condition is proper,
it will be executed as like value "0" will be assigned to a and then it will check the if condition.
basically when we put any condition in if condition it check 0/1 like if (p==5) if p value is 5 then for this condition it will be something like if(1) in other scenario like if p is not equal to 5 then statement will be like if(0).
Such thing is happening in the given partial code, the last statement will be like if (0), which is false and control will go to else part. so that answer will be a is zero. However if you put a=5 then it will print a i non zero.
Report Error
Report Error
Please Login First Click Here