In C/C++ style notation, which of the following is NOT an integer constant?
-
A0
-
B-8
-
C+1074
-
D-8.1
-
E42
Answer
Correct Answer: -8.1
Explanation
Introduction / Context:Literals (constants) in programming languages are categorized by type—integer, floating-point, character, string, etc. Being able to recognize integer vs. floating-point constants is foundational for understanding type rules and compiler behavior.
Given Data / Assumptions:
- We use conventional C/C++ syntax for numeric literals.
- Leading sign (+ or −) is treated as a unary operator applied to a literal.
- Presence of a decimal point indicates a floating-point literal unless otherwise suffixed.
Concept / Approach:
An integer constant contains only digits (optionally with base prefixes/suffixes) and no decimal point. A floating-point constant contains a decimal point and/or exponent part with a fractional component. Thus, any literal with a decimal point like '-8.1' is not an integer constant.
Step-by-Step Solution:
Check each option for a decimal point.'0', '-8', '+1074', '42' → all are integers (sign is not part of the literal token in some compilers, but value is integer).'-8.1' contains a decimal point → floating-point literal.Therefore, the non-integer constant is '-8.1'.Verification / Alternative check:
Compiling small snippets confirms types via typeof or format specifiers (e.g., printf with %d vs. %f).
Why Other Options Are Wrong:
- 0, −8, +1074, 42: valid integer constants in typical languages.
Common Pitfalls:
Treating a leading '+' as invalid—most languages accept it; confusing a minus sign with part of the literal vs. unary negation (type remains integer).
Final Answer:
-8.1