Identify the construct that is not a user-defined data type in C/C++ among the following: (1) struct book { char name[10]; float price; int pages; }; (2) long int l = 2.35; (3) enum day { Sun, Mon, Tue, Wed };

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:

  • (1) A structure declaration named book that introduces a composite record type.
  • (2) A variable declaration using the built-in type long int with an initializer.
  • (3) An enumeration declaration named day that creates a distinct type with named constants.


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:

  • Option 1: Incorrect because struct book is a user-defined type.
  • Option 3: Incorrect because enum day is a user-defined type.
  • Option Both 1 and 2: Incorrect because only (2) is not user-defined.
  • None of the above: Incorrect because a correct choice exists, namely (2).


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

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