In the C programming language, which of the following identifiers is not a valid variable name under C's identifier rules (letters, digits, and underscores only; must not start with a digit; no spaces; keywords not allowed)?

Electronics and Communication Engineering Microprocessors Difficulty: Easy
Choose an option
  • A
    _temp
  • B
    1alpha
  • C
    alpha1
  • D
    total_sum

Answer

Correct Answer: 1alpha

Explanation

Introduction / Context:Variables in C must follow strict identifier rules to ensure the compiler can tokenize and parse code unambiguously. This question tests recognition of C identifier syntax and common invalid patterns such as starting with a digit or inserting spaces or special characters.

Given Data / Assumptions:

  • Language context: C (ANSI C/C99/C11 identifier rules).
  • Allowed characters: letters A–Z/a–z, digits 0–9, and underscore _.
  • First character must be a letter or underscore, not a digit.
  • Keywords (e.g., int, float) cannot be used as identifiers.

Concept / Approach:The validity of an identifier is checked against: first-character rule, allowed character set, and reserved-word avoidance. We evaluate each option against these rules and pick the only one that violates them.

Step-by-Step Solution:

Step 1: Check '_temp' → begins with underscore and uses only letters/underscore → valid.Step 2: Check '1alpha' → begins with digit '1' → violates first-character rule → invalid.Step 3: Check 'alpha1' → starts with a letter; digits allowed after first character → valid.Step 4: Check 'total_sum' → letters and underscore only; starts with letter → valid.

Verification / Alternative check:Informal compiler mental check: if you wrote 'int 1alpha;' a compiler would emit an error at the '1' because tokens cannot begin with a digit for identifiers. The others would compile (assuming no prior conflicting declarations).

Why Other Options Are Wrong:

  • _temp: Valid because underscore is allowed as the first character.
  • alpha1: Valid; digits are allowed after the first character.
  • total_sum: Valid; underscores are allowed anywhere after the first position as well.

Common Pitfalls:

  • Believing digits are entirely disallowed in identifiers. They are allowed, just not as the first character.
  • Confusing C with other languages' naming conventions; C's underscore-leading identifiers are permitted (though some names may be reserved in system headers).

Final Answer:1alpha

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