What will be output if you will execute following c code?

Code
  1.  #i ain()

  2. {

  3. float p=1,q=2,r=-2,a;

  4. a=avg(p,(q=4,r=-12,q),r);

  5. printf("%f",a); return 0;

  6. }

  7. float avg(float x,float y,float z)

  8. {

  9. return (x+y+z)/3;

  10. }
Copyright GeekInterview.com

a) 1.000000
b) 0.333333
c) -2.333333
d) 1

Questions by lalithakasiraj

Showing Answers 1 - 9 of 9 Answers

bavya

  • Feb 15th, 2013
 

avg(1,-6,-2)/3 =-2.3333

  Was this answer useful?  Yes

Howard Lee Harkness

  • Apr 4th, 2013
 

The real answer is that any programmer who would write this kind of code should be given the opportunity to work for the competition.

The sequence expression (q=4,r=-12,q) evaluates to 4 (the last element), with the side-effect of assigning r the value -12. So, avg(1,4,-12) = -7/3 = -2.33...

  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