Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
XML
#include <stdio.h>
#include <conio.h>
void main()
{

int x=2,y=3;
x=y++ + x++;
y=++y + ++x;
printf("%d%d",x,y);
getch();



THE OUTPUT OF CODE IS 7 AND 12


i not understand how this output comes plz help me
Posted

1) x=2, y=3
2) x = 3 + 2 -> x++ , y++ -> x=6 y=4
3) y = (y+1) + (x+1) -> x= 7 , y = 12
 
Share this answer
 
x=y++ + x++;


With this line u got x=(3)+(2)=5
now post increment will done
so x++ gives (5+1)=6
y++ gives (3+1)=4

y=++y + ++x;


From this line you got y=12 i.e
pre increment will be done before execution of expression.
so now x=7,y=5
y=(5)+(7)=12
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900