By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,516 Members | 1,369 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,516 IT Pros & Developers. It's quick & easy.

Increment and decrement

P: 1
Expand|Select|Wrap|Line Numbers
  1.  
  2. #include<stdio.h>
  3. main()
  4. {
  5. int i=5;
  6. printf("%d %d %d %d %d \n",i,i++,++i,i++,i);
  7. }
  8.  
  9.  
In the TurboC compiler the output is
8 7 7 5 5
In the GCC compiler the output is
8 7 8 5 8

why the difference?
Feb 1 '16 #1
Share this Question
Share on Google+
1 Reply


P: 15
What you have is undefined behavior. The order in which function arguments are evaluated is unspecified in the standard, so how they are evaluated is compiler specific. Here is a link to Kernigan & Ritchie. See chapter 2.12, (specifically page 49) for an example similar to yours.
Feb 1 '16 #2

Post your reply

Sign in to post your reply or Sign up for a free account.