What are the naming rules for C language identifiers?
Here are the rules for naming identifiers in C language:
- Identifiers must start with a letter (uppercase or lowercase) or an underscore (_).
- Identifiers can only consist of letters (uppercase or lowercase), numbers, and underscores (_).
- Identifiers cannot start with a number.
- Identifiers cannot be keywords, such as if, for, while, etc.
- Identifiers are case-sensitive, for example, “apple” and “Apple” are considered as different identifiers.
- There is no restriction on the length of the identifier, but it is usually recommended not to exceed 32 characters.
For example, legal identifiers include: name, _count, num1, MAX_VALUE, etc.; illegal identifiers include: 123abc (starts with a number), if (keyword), $money (contains illegal character $).