-6

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!

AAEM
  • 1,837
  • 2
  • 18
  • 26
  • we cannot use $ sign in variable name, only underscore is permitted, among special character – Pramod Yadav Sep 08 '17 at 08:31
  • 3
    GCC (and maybe others) has an extension that allows `$` in identifiers. – Quentin Sep 08 '17 at 08:37
  • 1
    dude, letter means `a-z` and `A-Z`. digit means `0-9`. underscore means `_`. – Yves Sep 08 '17 at 08:43
  • @Yves: That is not actually true (regarding letters), though common wisdom _is_ that you should restrict yourself to single-code-point, unaccented Latin alphabet characters. – Lightness Races in Orbit Feb 14 '18 at 19:22
  • @Yves why this question has very low score? it made me banned from asking further question? – AAEM May 01 '18 at 11:30
  • @Ahmed You won't be banned. You got downvote because you didn't provide enough information. You said "the compiler did not complain", then you should have at least told us which kind of compiler you were using. – Yves May 01 '18 at 14:41
  • @Ahmed Anyway, no need to worry about the downvote. Stackoverflow is not very kind for newbie. – Yves May 01 '18 at 14:43
  • @LightnessRacesinOrbit how can i improve my question to get rid of the down voting. this question and another one made me banned from asking any more questions – AAEM May 03 '18 at 00:39
  • @Ahmed: FWIW, I did not downvote this question. I don't know why it got so many downvotes. But it takes much more than two questions to get a ban. – Lightness Races in Orbit May 03 '18 at 08:57
  • @LightnessRacesinOrbit So, is there a way to know who down voted it ? – AAEM May 03 '18 at 11:44
  • @Ahmed: No, there isn't. – Lightness Races in Orbit May 03 '18 at 14:18
  • @LightnessRacesinOrbit Is there a way to improve my question? I tried edit it more than one time to make it better but this does not change anything – AAEM May 04 '18 at 14:07
  • @Ahmed: No further improvement necessary that I can see. – Lightness Races in Orbit May 04 '18 at 14:22
  • @LightnessRacesinOrbit Is not this a boring thing to wait all that time in spite of the effort exerted in improving all the question. So what should i do? to wait ? or to create another account to be able to ask questions? – AAEM May 04 '18 at 14:35
  • @Ahmed: Provide some quality answers to existing questions until the ban is lifted. Evading it by creating another account is the worst thing you can do. What's boring though is being faced with low quality questions all the time :) If you have any further questions I suggest contacting a moderator. – Lightness Races in Orbit May 04 '18 at 15:23
  • @LightnessRacesinOrbit How can i contact a moderator? – AAEM May 04 '18 at 15:57
  • @Ahmed: https://meta.stackoverflow.com/q/255583/560648 Please get better at performing research before asking. – Lightness Races in Orbit May 04 '18 at 16:48
  • @LightnessRacesinOrbit I know that you have a lot of experience about this since you have many reputation points, that is why i asked – AAEM May 04 '18 at 16:51
  • @Ahmed: As you can imagine, we get asked a _lot_ which is why the information is written down already for you to find yourself instead. :) – Lightness Races in Orbit May 04 '18 at 17:12

3 Answers3

2

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++

ssovukluk
  • 438
  • 3
  • 14
0

I tried to use it and the compiler did not give error.

Just don't do it, even if your current compiler supports it (as Quentin points out in a comment). It's not in the standard, so your code will not be portable to other environments, or even to the same compiler using a different standard (try the GCC options -ansi, -std=c++11 etc.). The best that can happen is that you get an error on compilation, the worst is undefined behaviour you'll be hunting after for many hours.

Murphy
  • 3,827
  • 4
  • 21
  • 35
-1

Its totally depends on the complier you are using, as I am using in TC 4.5 it show this error:

Compiling DEMO.C:

Illegal character '$' (0x24)

Some compiler may support it.

iamsankalp89
  • 4,607
  • 2
  • 15
  • 36