What is the correct answer for cout << a++ << a;?

前端 未结 4 457
无人及你
无人及你 2020-11-22 16:12

Recently in an interview there was a following objective type question.

int a = 0;
cout << a++ << a;

Answers:

a. 10

4条回答
  •  难免孤独
    2020-11-22 16:46

    The correct answer is to question the question. The statement is unacceptable because a reader cannot see a clear answer. Another way to look at it is that we have introduced side-effects (c++) that make the statement much harder to interpret. Concise code is great, providing it's meaning is clear.

提交回复
热议问题