C++ MCQs (multiple choice questions) focuses on “User Defined Types”. One shall practice these MCQs to improve their C++ programming skills needed for various interviews , placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our multiple choice questions come with detailed explanation of the answers which helps in better understanding of C++ concepts.
C multiple choice questions on “User Defined Types” along with answers, explanations and/or solutions:
Q 1. Which keyword is used to define the user defined data types?
A. def
B. union
C. type
D. Typedef
Show Answer
Answer:-D. TypedefExplanation
Typedef is used to define user defined datatypes. eg: typedef int INT; INT a; here INT is used defined data type.Q 2. Identify the correct statement.
A. typedef will not creates synonyms of existing types
B. typedef create different types
C. typedef create own types
D. typedef does not create different types. It only creates synonyms of existing types
Show Answer
Answer:-D. typedef does not create different types. It only creates synonyms of existing typesExplanation
By using typedef, we can create a type of pre-existing type only not our own type of data.Q 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
Show Answer
Answer:- D.It allow one same portion of memory to be accessed as different data typesExplanation
Union is used to define the data types of our choice and it will store the data type in one location make them accessible.Q 4. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
typedef int num;
num a = 10, b = 15;
num c = a + b + a – b;
cout << c;
return 0;
}
A. 10
B. 20
C. 30
D. 25
Show Answer
Answer:-B. 20Explanation
In this program, we are manipulating the numbers and printing the result using user-defined data types. Output: $ g++ user.cpp $ a.out 20Q 5. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int i;
enum month
{
JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,DEC
};
for (i = JAN; i <= DEC; i++)
cout << i;
return 0;
}
A. 012345678910
B. 0123456789
C. 01234567891011
D. 01234567891011122
Show Answer
Answer:-A. 012345678910Explanation
In this program, we are defined the data types as enumerator and printing its value in a order. Output: $ g++ user1.cpp $ a.out 012345678910Q 6. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
typedef int num;
typedef char let;
let w = “steve”;
num a = 10, b = 15;
num c = a + w;
cout << c;
return 0;
}
A. 10steve
B. steve10
C. compile time error
D. compile but not run
Show Answer
Answer:-C. compile time errorExplanation
Error: invalid conversion from ‘const char*’ to ‘let {aka char}’.Q 7. What is the syntax of user-defined data types?
A. def NameByUser ExistingData
B. typedef NameByUser ExistingDataType
C. def NameByUser ExistingDataType
D. typedef ExistingDataType NameByUser
Show Answer
Answer:-D. typedef ExistingDataType NameByUserExplanation
correct syntax is typedef ExistingDataType NameByUser. typedef int INT; (typedef existing-datatype New-name;).Q 8. How many types of user-defined data type are in c++?
A. 1
B. 2
C. 3
D. 4
Show Answer
Answer:-C. 3Explanation
There are three types of user-defined data types. They are typedef, union, enumerator.Q 9. What is the scope of typedef defined data types?
A. inside that block only
B. outside the program
C. whole program
D. main function
Show Answer
Answer:-C. whole programExplanation
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.Q 10. How many types of models are available to create the user-defined data type?
A. 1
B. 2
C. 3
D. 4
Leave a Reply