Variable Naming – Why Should Identifiers Not Begin with a Number?

namingvariables

Most programming languages appear to be designed to not allow one to declare an identifier that starts with a number. I was just curious to know the reason. I have already searched the web, but couldn't find a satisfactory explanation.

Best Answer

In C/C++, a number followed by a letter is considered to be a numeric constant and the string that follows, qualifies the type of the constant. So for example (these are VC++, not sure how standard they are):

  • 0 - signed integer
  • 0l - signed long integer
  • 0u - unsigned integer
  • 0i64 - 64 bit signed integer

So a) it is easier for the lexer as Daniel said but also b) it makes an explicit distinction since 0y might be a variable but 0u would never be. Plus other qualifiers, like "i64" were added way later than "l" or "u" and they want to keep the option open of adding more if needed.