Here is a listing of 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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?
#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) 20
b) 15
c) 30
d) 25
View Answer
Explanation: 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?
#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
View Answer
Explanation: In this program, we are defined the data types as enumerator and printing its value in a order.
Output:
$ g++ user1.cpp $ a.out 012345678910
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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: There are two types of models. They are references to built-in types and multipart types.
Sanfoundry Global Education & Learning Series – C++ Programming Language.
To practice all areas of C++ language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Check Programming Books
- Apply for C++ Internship
- Practice Programming MCQs
- Check C++ Books
- Apply for Computer Science Internship