+ 1

The unpredictability of the order of Evaluation of Subexpressions

#include <iostream.h> main() { int n=5, x; x=++n*--n; cout<< "n = "<<n<<", x="<<x<<endl; cout<<++n<<" "<<++n<<" "<<++n<<endl; }

15th Feb 2018, 1:30 AM
Aksh Rathore
Aksh Rathore - avatar
5 Réponses
+ 8
yes, this is bad practise.
15th Feb 2018, 2:08 AM
jay
jay - avatar
+ 6
Multiple prefix, postfix operators used on a single variable between two sequence points would result in undefined behaviour. The end result is dependent on the compiler.
15th Feb 2018, 5:21 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
operator precedence comes into play then , remembering them will be a life saver. c++ is good in this aspect , js gives weird output in more cases. c++ precedence chart http://en.cppreference.com/w/cpp/language/operator_precedence
15th Feb 2018, 5:41 AM
Morpheus
Morpheus - avatar
0
I am unableto understand this. Can anyone help?
15th Feb 2018, 4:13 AM
Aksh Rathore
Aksh Rathore - avatar