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

Regarding increment operator implementation and output explanation

P: 1
#include<stdio.h>
int main()
{
int i=10;
printf("%d\t%d\t%d\t%d",i++,i++,i++,i++);
}
why output is
12 11 10
and not
10 11 12 ?
Oct 22 '16 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
C++ evaluates variables before doing things with them. The order of evaluation might be left to right or it may be right to left or some other way. The C++ spec doesn't care.

If you have changed a variable more then once in a statement, your results are indeterminate.
Oct 22 '16 #2

Post your reply

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