Why int $ = 10; is NOT throwing any error in C++?

Viewed 39

According to the identifier declaration rules in c++.

The general rules for naming variables are:

  1. Names can contain letters, digits and underscores
  2. Names must begin with a letter or an underscore (_)
  3. Names are case sensitive (myVar and myvar are different variables)
  4. Names cannot contain whitespaces or special characters like !, #, %, etc.
  5. Reserved words (like C++ keywords, such as int) cannot be used as names

CODE

#include <bits/stdc++.h>

using namespace std;

int main(void)
{
    int $ = 10;
    cout << $ << '\n';
    return 0;
}

OUTPUT

10

But according to rule 2 and 4, the name must begin with number or any case alphabet.

But here the variable name is $ (which is a special character).

So, why it is compiling and executing successfully?

0 Answers
Related