250+ TOP MCQs on User Defined Types and Answers

C++ multiple choice questions on “User Defined Types” along with answers, explanations and/or solutions:

1. Which keyword is used to define the user defined data types?
a) def
b) union
c) typedef
d) type

Answer: c
Clarification: Typedef is used to define user defined datatypes.
eg:
typedef int INT;
INT a;
here INT is used defined data type.

2. Identify the correct statement.
a) typedef does not create different types. It only creates synonyms of existing types
b) typedef create different types
c) typedef create own types
d) typedef will not creates synonyms of existing types

Answer: a
Clarification: By using typedef, we can create a type of pre-existing type only not our own type of data.

3. What does the data type defined by union will do?
a) It allow one different portion of memory to be accessed as same data types
b) It allow one same portion of memory to be accessed as same data types
c) It allow one different portion of memory to be accessed as different data types
d) It allow one same portion of memory to be accessed as different data types

Answer: d
Clarification: Union is used to define the data types of our choice and it will store the data type in one location make them accessible.

4. What will be the output of the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         typedef int num;
  6.         num a = 10, b = 15;
  7.         num c = a + b + a - b;
  8.         cout << c;
  9.         return 0;
  10.     }

a) 20
b) 15
c) 30
d) 25

Answer: a
Clarification: In this program, we are manipulating the numbers and printing the result using user-defined data types.
Output:

$ g++ user.cpp
$ a.out
20

5. What will be the output of the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int i;
  6.         enum month
  7.         {
  8.             JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,DEC
  9.         };
  10.         for (i = JAN; i <= DEC; i++)
  11.             cout << i;
  12.         return 0;
  13.     }

a) 012345678910
b) 0123456789
c) 01234567891011
d) 01234567891011122

6. What will be the output of the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         typedef int num;
  6.         typedef char let;
  7.         let w = "steve";
  8.         num a = 10, b = 15;
  9.         num c = a + w;
  10.         cout << c;
  11.         return 0;
  12.     }

a) 10steve
b) steve10
c) compile time error
d) compile but not run

Answer: c
Clarification: Error: invalid conversion from ‘const char*’ to ‘let {aka char}’.

7. What is the syntax of user-defined data types?
a) typedef ExistingDataType NameByUser
b) typedef NameByUser ExistingDataType
c) def NameByUser ExistingDataType
d) def NameByUser ExistingData

Answer: a
Clarification: correct syntax is typedef ExistingDataType NameByUser.
typedef int INT; (typedef existing-datatype New-name;).

8. How many types of user-defined data type are in c++?
a) 1
b) 2
c) 3
d) 4

Answer: c
Clarification: There are three types of user-defined data types. They are typedef, union, enumerator.

9. What is the scope of typedef defined data types?
a) inside that block only
b) whole program
c) outside the program
d) main function

Answer: b
Clarification: We are defining the user-defined data type to be availed only inside that program, if we want to use anywhere means we have to define those types in the header file.

10. How many types of models are available to create the user-defined data type?
a) 1
b) 2
c) 3
d) 4

Answer: b
Clarification: There are two types of models. They are references to built-in types and multipart types.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top