Rules for identifiers in C
- The first character must be an alphabet or underscore.
- Must consist of only letters, digits, or underscore.
- Only the first 31 characters are significant.
- Cannot use a keyword.
- Must not contain white space.
Example:
| Variable name | Valid/Invalid | Why? |
| abc | Valid | No rules were violated. |
| XYZ | Valid | No rules were violated. |
| 1st | Invalid | The first character is a digit. (Violated 1st rule) |
| _health | Valid | No rules were violated. |
| #dontspoiltheendgame | Invalid | Starts with the special symbol.(Violated 1st & 2nd rule). |
| max number | Invalid | Contains whitespace. (Violated 5th rule) |
| max_number | Valid | No rules were violated. |
| float | Invalid | Makes use of a reserved keyword. (Violated 4th rule) |
| Price$1 | Invalid | Contains a special symbol. (Violated 2nd rule) |
| Number#1 | Invalid | Contains a special symbol. (Violated 2nd rule) |
| Number_1 | Valid | No rules were violated. |
Comments
Post a Comment