According to the identifier declaration rules in c++.
The general rules for naming variables are:
- Names can contain letters, digits and underscores
- Names must begin with a letter or an underscore (_)
- Names are case sensitive (myVar and myvar are different variables)
- Names cannot contain whitespaces or special characters like !, #, %, etc.
- 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?