C++ Quiz49 of 173
Difficulty:
⬅️ Prev: 119Quiz ID: 120Next: 121 ➡️

According to the C++23 standard, what is the output of this program?

#include <iostream>

int main() {
  int a = 10;
  int b = 20;
  int x;
  x = a, b;
  std::cout << x;
}
Hint

Operator precedence.

Reveal answer

10

Explanation

The comma operator has the lowest precedence of all C++ operators (specifically lower than =). In this example it separates the two expressions x = a and b.

First x = a is evaluated, setting x to 10. Then, b is evaluated, which does nothing.

⬅️ Prev: 119Quiz ID: 120Next: 121 ➡️