In C, which of the following is <em>not</em> a valid variable name (identifiers may include letters, digits, and underscores, cannot contain spaces, and must not start with a digit)?
Electronics and Communication Engineering
Microprocessors
Difficulty: Easy
Choose an option
-
Ap o t
-
Bpo_t
-
Cp_o_t
-
Dpot
Answer
Correct Answer: p o t
Explanation
Introduction / Context:C identifiers must follow lexical rules so the compiler can tokenize code reliably. This question targets the prohibition of whitespace inside identifiers.
Given Data / Assumptions:
- Permitted: letters, digits, underscore.
- Not permitted: spaces, punctuation like commas or hyphens within an identifier.
- First character cannot be a digit.
Concept / Approach:Test each candidate against the rules, especially whether it contains spaces. Any name with a space is not a single identifier.
Step-by-Step Solution:
Check 'p o t' → contains spaces → not a single token → invalid identifier.Check 'po_t' → letters and underscore only → valid.Check 'p_o_t' → letters and underscores only → valid.Check 'pot' → letters only → valid.Verification / Alternative check:Attempting to compile 'int p o t;' would be parsed as tokens 'int', 'p', 'o', 't' (three separate identifiers), producing a syntax error. The others would compile (barring redefinitions).
Why Other Options Are Wrong:
- po_t: Allowed; underscores are valid and common.
- p_o_t: Allowed; multiple underscores are still valid.
- pot: Allowed; simple alphabetic identifier.
Common Pitfalls:
- Assuming underscores are disallowed—C fully permits them.
- Confusing spaces with underscores; only underscores are legal in identifiers.
Final Answer:p o t