The Gateway to Computer Science Excellence
+1 vote
44 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 (3.9k points) | 44 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 (7.7k points)

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
50,666 questions
56,154 answers
193,757 comments
93,719 users