In what order will the following line of code be executed?
Is my assumption correct that the sequence of execution will be in the following order.Code:while((char c = cin.get()) != 'q')
1) cin.get() gets called
2) its return value is assigned to c
3) then c's value is compared to 'q'
Is it correct? I was reading Thinking in C++ by Bruce Eckel and in the third Chapter I read this
Excerpt from the book:
For example, you cannot have any parentheses. That is, you cannot say:
while((char c = cin.get()) != 'q')
The addition of the extra parentheses would seem like an innocent and useful thing to do, and because you cannot use them, the results are not what you might like. The problem occurs because ‘!=’ has a higher precedence than ‘=’, so the char c ends up containing a bool converted to char. When that’s printed, on many terminals you’ll see a smiley-face character.