What is result for of this C Code block?

What is the result
main()
{
int x=15;
printf("%d %d %d",x!=15,X=20,X<30);
}

Questions by jyotirmoyy

Showing Answers 1 - 30 of 30 Answers

sapan

  • Sep 8th, 2011
 

if x=X here then
output:

1201

because printing is done from right to left in printf and here,
x<30 means true and in c it is 1 , so output is 1

x=20 means x is assigned to 20 now and then itz value is printed and


x!=15 will give true becuz now the value is 20 and in c true means 1

  Was this answer useful?  Yes

varsha

  • Sep 9th, 2011
 

1 1 0

  Was this answer useful?  Yes

somgupta

  • Sep 10th, 2011
 

Ans : 1 20 1
Reason : in printf() calculation is done from right to left so
step 1- x<30 is evaluated n its results will be 1(true) then
step 2- x=20 is is evaluated n its results will be 20 (as 20 is assign into x ) then
atep 3- x!=15 is evaluated n its results will be 1(true) since last values of x is 20 not 15
finally results of all steps are printed from left to right.

  Was this answer useful?  Yes

chandrika

  • Sep 15th, 2011
 

compile time error

  Was this answer useful?  Yes

Note: printf works from right to left (r to L)

in first x<30 a test condition is there so output of dat test is true which means 1 in c so print 1

in second assingment is happing so it assing value n den print value of x which is equal to 20 now

in 3 condition is trueso it will print 1

o/p=1201

  Was this answer useful?  Yes

suresh

  • Feb 14th, 2014
 

1 20 20

  Was this answer useful?  Yes

The behavior is undefined; the arguments to printf aren't guaranteed to be evaluated in any particular order. The *result* of each expression is guaranteed to be passed in the order specified, but that's not the same thing. Its not guaranteed that x!=15 will be evaluated before x=20, and its not guaranteed that x will be evaluated after x=20. The result could be "1 20 20" or "1 20 15" or "0 20 20" or something completely different.

  Was this answer useful?  Yes

SAnket

  • Apr 8th, 2015
 

It will give error!! X : undeclared identifier.
if both are small x then it give 1 20 1 as result

  Was this answer useful?  Yes

Swinky Sardana

  • Apr 15th, 2015
 

1 20 20

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions