Find the output of C Program ?

main()
{
int x=20,y=35;
x = y++ + x++;
y = ++y + ++x;
printf("%d %d\n",x,y);
} ?

While calculating the x value, x & y values are post incremented. So, the values of x & y are added and then incremented i.e. x=56, y=36

While calculating the y value, x & y values are preincremented, so x & y values are incremented and then added i.e x=57, y=37.

{ x=y++ + x++; } equal to


x=y+x;//35+20
x++; //56
y++; //36
}

y=++y + ++x; is equal to


++y;//37
++x;//57
y=y+x;//37+57
}

Output:

x=57
y=94

Categorized in:

C

Tagged in:

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Share Article:

Leave a Reply

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock