What are the naming rules for C language identifiers?

Here are the rules for naming identifiers in C language:

  1. Identifiers must start with a letter (uppercase or lowercase) or an underscore (_).
  2. Identifiers can only consist of letters (uppercase or lowercase), numbers, and underscores (_).
  3. Identifiers cannot start with a number.
  4. Identifiers cannot be keywords, such as if, for, while, etc.
  5. Identifiers are case-sensitive, for example, “apple” and “Apple” are considered as different identifiers.
  6. 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 $).

bannerAds