Thread: small but odd!
View Single Post
Old 11-30-2005, 07:18 PM   #6 (permalink)
mgoldb2
 
Super Techie

Join Date: Jun 2005

Posts: 274

mgoldb2

Default Re: small but odd!

Quote:
Originally posted by i_learn
[B]
int j=1,q;

q=j++ + ++j + j++;
printf("%d %d",q,j);
getch();
clrscr();
q=j++ + ++j + ++j;
printf("%d %d",q,j);
getch();
}
it not that difficult if you understand how it works

6 4

16 7

would be the out put

let me explain

++j increment J by 1 before operation
J++ increment J by 1 after operation

for example the first one
j++ + ++j + j++

first thing done is (j++ + ++j)
first number is incremented after secound one before so you get
1+2=3
now that it done with the operation J is increase one for the J++ so now j =3
3+3=6 (j++ is incremented after operation)
and after that all done J increase to 4

sorry if I was confusing am trying to be clear.
mgoldb2 is offline