I got an interesting program what I can't understand completely.
#include <iostream>
#include <typeinfo> //added by me to check 'h' variable type
using namespace std;
int main()
{
int a = -1, b =1, c = 1, d = 0, e = 2, f = 2, g = 0;
int h = f-- && e++ && d++ && c-- || b++ || a++; //interesting part
cout << "f:" << f << << " e:" << e << " d:" << d << " c:" << c << " b:" << d
<< " a:" << a << " g:" << g << " h:" << h <<endl;
cout << "h variable type :" << typeid(h).name() << endl;
return 0;
}
so the 'h' variable is the problem, its adding and substracting while reach the c-- part (c-- never happens) and the a++ never happens too just like c--. Why is that? If im right its something like: h = f-- (true) and e++ (true) and d++ (true) and c-- (which is false (if c=0) else happens) or b++ which is (true) or a++ (which is also true). the 'h' variable type is int. but its looks like a boolean to me.
Edit:
Okay, so the help with you guys i figured out how it works, and what are the pre and postfix operands, many thanks!
Now i started to print it out how it works, and i found a little weird thing. if i run this
if(f-- && e++ && d++ & c-- || b++)
cout << "f:" << f << " e:" << e << " d:" << d << " c:" << c << " b:" << b << endl;
it gives the following: f:1 e:3 d:1 c:1 b:2 everything is incremented and decremented except the C variable. which is little weird. Anyone any thought while C variable is the only one which is not decremented and why?