interesting programming question...

notfred

Lifer
Feb 12, 2001
38,241
4
0
int var = 10;
cout << (++var--)*10;
cout << "\n";
cout << (var*10);


should print:
110
100

Or is the ++var-- even allowed?

I dunno, I just thought of that.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
either no one knows, or someone's compiling it right now to check and see if it works :)
 

Derango

Diamond Member
Jan 1, 2002
3,113
1
0
I don't see why not...although I haven't compiled it or anything :)

Its just strange that you'd want to do somthing like that.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0


<< although you could combine the couts into one line...... >>



No I couldn't. I could combine them into 2 lines, but not one.
 

nd

Golden Member
Oct 9, 1999
1,690
0
0
The line with (++var--) got a compiler error for me using GCC 2.96:

testasdf.cpp:6: non-lvalue in increment
 

br0wn

Senior member
Jun 22, 2000
572
0
0


<< cout << (++var--)*10; >>



Although some compilers allow the above statement, it is consider not a good practice (violating C standard (ANSI C?)) to change the value of a variable twice in a statement.