Skip to main content

Identifiers and rules

Short answer

Identifiers are user-defined names for variables, functions, etc. Rules: only letters, digits, underscore; first character not a digit; no spaces or special symbols; cannot be keywords; case-sensitive. Valid: _count, sum1; invalid: 2x, my-var, float.

What are identifiers? List the rules to define valid C identifiers.

Identifiers are the names given by the programmer to variables, functions, arrays, structures and other user-defined items in a program, for example total, sum1, calculate_area.

Rules for valid identifiers

  1. Only letters (A-Z, a-z), digits (0-9) and the underscore (_) are allowed.
  2. The first character must be a letter or an underscore, not a digit (2num is invalid).
  3. No spaces or special characters such as - @ # $ % are allowed (my-var is invalid).
  4. A keyword cannot be used as an identifier (int, float, while).
  5. C is case sensitive, so Total, total and TOTAL are three different identifiers.
  6. The name should be meaningful. Only a limited number of leading characters are guaranteed to be significant (31 in C89; 63 for internal names in C99).

Examples: valid are total_marks, _rate, num2; invalid are 2num, my-var, float.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Programming chapter 3 questions →