[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.
Interview Questions and Answers :: Tavant Technologies

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");

Answer:

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.

Post Your Answer Here:      Public      Private

Rate This: +0 -1
Report     

Post Your Reply Here:     

Report Error

Report Error

Please Login First Click Here

Rate This: +1 -0
Report     

Post Your Reply Here:     

Report Error

Report Error

Please Login First Click Here