C - Data Types - Discussion

You Are Here :: Home > C > Data Types - Discussion

 



Q.

Find the output of the following code snippet print?

int iNumber1 = 10, iNumber2 = 20;
if (iNumber1 = 0)
{
iNumber2 = 50;
}
printf("%d %d",iNumber1,iNumber2);

A. 0 20 B. 10 20
C. 0 50 D. 10 50

Answer: Option A
Explaination:

 


In the if condition. "=" is present instead of "==".In this case, "if" will try to assign the value rather than checking. So, 0 is assigned to iNumber1.Since 0 is assigned inside the "if", it will be evaluated to false. If any of number other than zero is assigned then it will be evaluated to true.Since, only iNumber1 is assigned with 0 and iNumber2 possess the value 20.



Discussion

Your Comments Goes here...
NameDiscussion