In the C programming language, which of the following identifiers cannot be used as a variable name (choose the reserved keyword that is invalid as an identifier)?

Difficulty: Easy

Correct Answer: else

Explanation:


Introduction:
In C programming, identifiers (variable, function, and type names) must follow strict lexical rules. A common beginner trap is attempting to use a reserved keyword as a variable name. This question checks understanding of C's identifier syntax and the reserved keyword set.


Given Data / Assumptions:

  • Language context: ANSI C / ISO C.
  • Candidate names: else, coal, ram, vendy.
  • Goal: identify the invalid variable name according to C rules.


Concept / Approach:

C identifiers must start with a letter or underscore and then may contain letters, digits, or underscores. However, no identifier may be a reserved keyword. Keywords have fixed meanings to the compiler and cannot be redefined as variable names. The token 'else' is a control-flow keyword paired with 'if' and 'else if' constructs, so it cannot be repurposed as an identifier.


Step-by-Step Solution:

Step 1: List the options and quickly check character legality (letters only) — all pass this basic test.Step 2: Compare each token against the C keyword list (auto, break, case, char, const, continue, default, do, double, else, enum, extern, float, for, goto, if, inline (C99), int, long, register, restrict (C99), return, short, signed, sizeof, static, struct, switch, typedef, union, unsigned, void, volatile, while, _Bool, _Complex, _Imaginary (C99)).Step 3: Recognize 'else' appears in the keyword set and is therefore invalid as a variable name.Step 4: Confirm that 'coal', 'ram', and 'vendy' are not keywords and follow identifier rules, so they are valid.


Verification / Alternative check:

Compilers will emit a syntax error if you attempt int else = 5; because the parser expects the keyword 'else' to follow an 'if' statement, not to declare an object.


Why Other Options Are Wrong:

'coal' – not a keyword; valid identifier.
'ram' – not a keyword; valid identifier (despite being a common acronym).
'vendy' – not a keyword; valid identifier.


Common Pitfalls:

Confusing natural-language words with keywords; assuming case-insensitive matching (C is case-sensitive; 'Else' would be valid, though discouraged). Avoid shadowing and pick descriptive names even when valid.


Final Answer:

else

More Questions from Microprocessors

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion