Answered Questions

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

    {geshibot language="c"} #i ain() { float p=1,q=2,r=-2,a; a=avg(p,(q=4,r=-12,q),r); printf("%f",a); return 0; } float avg(float x,float y,float z) { return (x+y+z)/3; }{/geshibot} a) 1.000000 b) 0.333333 c) -2.333333 d) 1

    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...

    bavya

    • Feb 15th, 2013

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