Search code examples
c++variablesstandards

Why the $ symbol can not be used as a part of an identifier?


I am a newbie to c++. I found the following statement in a C++ book: "In any C++ program, a variable name starts with a letter and contains only letters, digits, and underscores.The following are not variable name:"

2x             // a name must start with a letter
time$to$market // $ is not a letter, digit, or underscore
Start menu     // space is not a letter, digit, or underscore

The question is why time$to$market is not variable name? I tried to compile it and the compiler did not complain, the compiler i use is MinGW 32bit for c++ in QT. However it should complain!


Solution

  • There are different variations of compilers. One may compile faster, one may differ with some default settings for some reasons. I don't know what compiler you are using. But if you make a bit reaserch on your compiler you will see that $ is allowed. Try to compile with different compiler to catch up exactly with your book. Check this topic to see what does pure c++ mean. Because books usually teach pure language.

    What is pure C++