EmbLogic's Blog

issue in expression solution

#include<stdio.h>
main()
{
double d=3.2,x;
int i=2,y;
x=(y=d/i)*2;
printf(“%g\t %g\n”,(double)x,(double)y);
y=(x=d/i)*2;
printf(“%g\t %g\n”,(double)x,(double)y);
y=d*(x=2.5/d);
printf(“%g\n”,(double)y);
x=d*(y=((int)2.9+1.1/d));
printf(“%g\t %g\n”,(double)x,(double)y);
return 0;
}
its output is:

2     1
1.6     3
2
6.4     2

ques ?  how x=(y=1)*2 is 2.

2 Responses to issue in expression solution

  1. hemant.kumar says:

    x=(y=1)*2;
    first of all ,solve the expression with in the berackets i.e (y=1) it means you are going to multiply ‘y’ with 2 ,here y is 1

    take another example suppose x=(y=2)*6;
    your answer will be 12 ,
    2 is assigning to y and then the value of y is being multiplied by 6..

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>