what is diff b/w ++a and a++

Sep 12, 2008 at 3:44pm
What is the diff b/w ++a and a++ in the implication in b/w the assiengment..
plz tel it in basic language..
Sep 12, 2008 at 10:20pm
a++ first does everything on the line, and then adds 1 to a.
++a first adds 1 to a, and then does everything on the line.

(I think)
Last edited on Sep 13, 2008 at 2:25am
Sep 12, 2008 at 11:21pm
That's backwards.

MS explains what they are
http://msdn.microsoft.com/en-us/library/e1e3921c(VS.80).aspx

C++FAQ-Lite explains what they mean
http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-13.9 (start reading at #9)

http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-13.15

Also be sure to watch your Sequence Points MS: http://msdn.microsoft.com/en-us/library/d45c7a5d.aspx
Wikipedia: http://en.wikipedia.org/wiki/Sequence_point

Good luck!

[edit]
BTW. Wrong forum.
Last edited on Sep 12, 2008 at 11:21pm
Sep 13, 2008 at 2:25am
LOL so it is! Fixed post.
Sep 13, 2008 at 2:50am
Here's the way it is:
suppose you have something like:
a=5;
s=++a;
In this case s=6.
but when:
a=5;
s=a++;
s=5.
Sep 15, 2008 at 2:12am
that is correct, but also confusing.. to put it more plain
1
2
3
4
5
6
7
8
int a, b = 5, c;
// b++ increases b by 1 then returns the old value of b
a = b++; // a = 5, b = 6
//  So b++ increased b from 5 to 6, then returned 5 to a

// ++b increases b by 1 then returns the new value of b
c = b++; // c = 7, b = 7
// So ++b increased b from 6 to 7, then returned 7 to c 
Sep 17, 2008 at 3:26pm
hey thanx..
to ol who posted rep..

they wer really useful ..
Topic archived. No new replies allowed.