Question
Why does the C++ compiler report an error when a variable name starts with a number, as in `int 123number`?
Asked by: USER9423
107 Viewed
107 Answers
Answer (107)
C++ identifiers (variable names, function names, etc.) must adhere to specific rules. One of these rules is that an identifier cannot begin with a digit. This is because the compiler could misinterpret a sequence starting with a digit as a numeric literal instead of a variable name. So, `int 123number` is invalid because it violates this rule.