✏️ Explanatory Question
Which of the following are invalid variable names and why?
| BASICSALARY | _basic | basic-hra |
| #MEAN | group. | 422 |
| population in 2006 | over time | mindovermatter |
| FLOAT | hELLO | queue. |
| team’svictory | Plot # 3 | 2015_DDay |
| Variable Name | Status | Reason |
|---|---|---|
| BASICSALARY | Valid | Contains only letters. |
| #MEAN | Invalid | # symbol is not allowed. |
| population in 2006 | Invalid | Contains spaces. |
| FLOAT | Valid | Contains only letters. |
| team’svictory | Invalid | Apostrophe symbol is not allowed. |
| _basic | Valid | Underscore at beginning is allowed. |
| group. | Invalid | Dot (.) is not allowed. |
| over time | Invalid | Contains spaces. |
| hELLO | Valid | Contains only letters. |
| Plot # 3 | Invalid | Contains space and # symbol. |
| basic-hra | Invalid | Hyphen (-) is not allowed. |
| 422 | Invalid | Variable name cannot start with a digit. |
| mindovermatter | Valid | Contains only letters. |
| queue. | Invalid | Dot (.) is not allowed. |
| 2015_DDay | Invalid | Starts with a digit. |
#include
int main()
{
/* Valid Variable Names */
int BASICSALARY = 50000;
int _basic = 1000;
int FLOAT = 20;
int hELLO = 5;
int mindovermatter = 1;
printf("BASICSALARY = %d\n", BASICSALARY);
printf("_basic = %d\n", _basic);
printf("FLOAT = %d\n", FLOAT);
printf("hELLO = %d\n", hELLO);
printf("mindovermatter = %d\n", mindovermatter);
/* Invalid Variable Names */
/*
int #MEAN = 10;
int population in 2006 = 50;
int basic-hra = 200;
int 422 = 15;
int queue. = 5;
int 2015_DDay = 100;
*/
return 0;
}
BASICSALARY = 50000
_basic = 1000
FLOAT = 20
hELLO = 5
mindovermatter = 1