a++ and ++a?

+1 Thai Bui · November 14, 2015
void main(void)

{
int a,b;
a=3;
b=a++ + ++a;
printf("%d,%d,%d,%d",b,a++,a,++a);
getch();

}

Post a Reply

Replies

Oldest  Newest  Rating
0 Thai Bui · November 16, 2015
thank you c student I think it's the best answer:"
C has the concept of undefined behavior, i.e. some language constructs are syntactically valid but you can't predict the behavior when the code is run."
0 Scott Walker · November 14, 2015
Not 100%  sure what you're wanting but I presume you're after the difference between them both.

i++ would increment i after that part of the code whilst ++i would increment during the code.

E.G.



int i = 0;
cout << ++i; //answer would be 1




int i = 0;
cout << i++; // answer would be 0
cout << i; // But is now 1



I used C++ rather than C but the concept is the same
0 c student · November 15, 2015
http://stackoverflow.com/questions/949433/why-are-these-constructs-using-undefined-behavior
  • 1

C

107,225 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator