What to name?

In C programming, identifiers are the names given to various entities such as variables, functions, arrays, structures, unions, etc. They are essentially the words a programmer uses to name these entities uniquely. Here are some rules and conventions for naming identifiers in C:

  1. Characters Allowed: An identifier can only have alphanumeric characters (a-z, A-Z, 0-9) and underscore (_). No other special characters or spaces are allowed.

  2. Start with Letter or Underscore: An identifier must start with a letter (either uppercase or lowercase) or an underscore. It cannot start with a digit.

  3. Case Sensitive: Identifiers in C are case-sensitive. This means example, Example, and EXAMPLE are considered three different identifiers.

  4. No Keywords: Identifiers cannot be the same as C keywords. For example, int, return, if, etc., cannot be used as identifiers.

  5. No Length Limit: Theoretically, there's no limit on the length of an identifier. However, it's subject to the limit imposed by the compiler, which typically supports identifiers of significant length (usually up to 31 characters are significant).

Examples of Valid Identifiers:

  • myVariable

  • count123

  • _tempValue


  • helloWorld

Examples of Invalid Identifiers:

  • 123count (cannot start with a digit)

  • int (keyword cannot be used as an identifier)

  • my variable (spaces are not allowed)

  • $sign (special characters other than underscore are not allowed)

  • return (keyword)

These rules help ensure that identifiers are consistent with the syntax of C and are recognizable by the compiler. It's also a good practice to choose meaningful and descriptive names for identifiers to make the code more readable and maintainable.