The Gateway to Computer Science Excellence
+1 vote
52 views
main( )
{
double x, d = 5.0;
int y ;
x = d * (x = 2.5/d);
printf(“x=%lf\n”,x);
x = d*(y=(int)2.5+1.5);
printf("x=%lf y=%d\n",x,y);
}
What is output of above program?
in Programming by Active | 52 views
0

x = d * (x = 2.5/d);

above statement will give undefined behavior, because it is modifying value of 'x' more than once b/w a sequence point.

1 Answer

0 votes

d=5.0

x=5.0 *(x=2.5/5.0) =2.5 {first printf output}

x=5.0 *(y=2+1.5) = 5.0*(y=3.5) 

x=15.0 y=3  {second printf output}

by Loyal

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
52,215 questions
59,993 answers
201,197 comments
94,663 users