- 2073 Chaitra · 2+3 marks
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
- Only letters (A-Z, a-z), digits (0-9) and the underscore (
_) are allowed. - The first character must be a letter or an underscore, not a digit (
2numis invalid). - No spaces or special characters such as
- @ # $ %are allowed (my-varis invalid). - A keyword cannot be used as an identifier (
int,float,while). - C is case sensitive, so
Total,totalandTOTALare three different identifiers. - 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)