Difficulty: Easy
Correct Answer: 2
Explanation:
Introduction / Context:
C and C++ provide several ways to define new types that aggregate or classify data. Distinguishing user-defined types from built-in types helps developers reason about declarations and understand how the type system maps to memory and semantics. This question asks you to identify which among three constructs is not a user-defined type.
Given Data / Assumptions:
Concept / Approach:
User-defined types are created via language constructs such as struct, class, union, enum, and typedef/using aliases. Both struct and enum introduce new, distinct types. In contrast, long int is a fundamental arithmetic type provided by the language; declaring a variable of type long int does not define a new type. Therefore item (2) is not a user-defined type; it is simply a variable of a built-in type, even if the numeric literal shown would be converted or truncated during initialization.
Step-by-Step Solution:
Evaluate item (1): struct book { ... }; defines a new structure type named book, so it is user-defined.Evaluate item (2): long int l = 2.35; uses a built-in type; no new type is introduced.Evaluate item (3): enum day { Sun, Mon, Tue, Wed }; defines a new enumeration type day; it is user-defined.Therefore, the only item that is not user-defined is (2).
Verification / Alternative check:
Compilers allow declarations of variables with long int without any prior type definition. However, attempting to use book or day without the corresponding struct or enum declarations would produce errors, confirming that (1) and (3) are truly user-defined types.
Why Other Options Are Wrong:
Common Pitfalls:
Confusing a variable declaration with a type definition. The presence of an initializer or a literal does not make a new type; only constructs like struct, class, enum, union, typedef, or using introduce types.
Final Answer:
2.
Discussion & Comments