3

Can anyone tells me why this is allowed in c++, and what is it?

const char* a = (10, "What");
Eduard Xue
  • 46
  • 2
  • 5
    It's the [comma operator](https://en.cppreference.com/w/cpp/language/operator_other#Built-in_comma_operator) – john Dec 19 '20 at 06:26
  • 10
    It's a pointless use of the comma operator. Whoever wrote the code should be dragged outside and made to read a C++ tutorial before being allowed back in anywhere near the codebase. – Jonathan Leffler Dec 19 '20 at 06:28
  • 3
    Note that there's a comma operator in the question title too. The LHS of the operator is ignorable; it doesn't do anything useful and could be thrown away. The RHS is where the action is. – Jonathan Leffler Dec 19 '20 at 06:29
  • This is the same as const char* a = "what"; – Rohit Dec 19 '20 at 06:37
  • I've to admit that this looked quite surprising and confusing to me as well. (...though I know the comma operator and have used it from time to time.) ;-) Maybe, it's the fact that this is simply non-sense and hence looks that unfamiliar even although it compiles. – Scheff's Cat Dec 19 '20 at 09:12

0 Answers0