How to use C language identifiers?

The naming rules for identifiers in the C language are used to name variables, functions, arrays, etc.

  1. It can only consist of letters (both upper and lower case), numbers, and underscores.
  2. The first character must be a letter or underscore.
  3. Identifiers are case-sensitive, for example, “abc” and “ABC” are different identifiers.
  4. You cannot use keywords in C language as identifiers, such as “int”, “for”, etc.
  5. There is no limit on the length of identifiers, but it is generally recommended not to exceed 32 characters.

Here are some examples:

  1. Valid identifiers: num, count, student_name, avg_score, _total, isPassed
  2. Invalid identifiers: 4num (starting with a number), for (keyword), studentName (containing illegal character “-“)

When using identifiers, the following standards should be followed:

  1. Identifiers should be descriptive and clearly reflect the meaning they represent.
  2. Choose between using camelCase or snake_case to name identifiers. In camelCase, the first letter of each word is capitalized, for example: getAvgScore; whereas in snake_case, words are separated by underscores, for example: get_avg_score.
  3. Avoid using abbreviations and simplified names, instead, use full words to name identifiers.
  4. Do not use the same identifier to name different variables or functions in the same scope, as this can lead to conflicts.
bannerAds