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

++ question for more inderstant

P: 1
#include<iostream>
using namespace std;
int main()
{

int a = 5;
int b = 5;
int c = 5;
int d = 5;
int e = 5;
int f = 5;
a = a++ + a++;
b = b++ + ++b;
c = ++c + c++;
d = ++d + ++d;
e = e++;
f = f + ++f;
cout << a++ << endl;
cout << ++b << endl;
cout << ++a << endl;
cout << c++ << endl;
cout << ++d << endl;
cout << d++ << endl;
cout << ++c << endl;
cout << ++f << endl;
return 0;
}
Nov 18 '15 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
Not good:

Expand|Select|Wrap|Line Numbers
  1. a = a++ + a++;
  2.  b = b++ + ++b;
  3.  c = ++c + c++;
  4.  d = ++d + ++d;
You are allowed to change the value of a variable only once in a statement.

The compiler is free to calculate the value of the variables in any order. Maybe left-to-right. Maybe right-to-left.

This code is called indeterminate. The same program compiled with different compilers can yield different results. Or maybe not.

Don't do this.
Nov 18 '15 #2

Post your reply

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