166
75.8k

100+ CPP Programming Solved MCQs

These multiple-choice questions (MCQs) are designed to enhance your knowledge and understanding in the following areas: Computer Science Engineering (CSE) , Information Technology Engineering (IT) , Programming Languages , Master of Science in Software Engineering (MSc SE) .

51.

Which of the following is true about templates?
1) Template is a feature of C++ that allows us to write one code for different data types.
2) We can write one function that can be used for all data types including user defined types. Like sort(), max(), min(), ..etc.
3) We can write one class or struct that can be used for all data types including user defined types. Like Linked List, Stack, Queue,..etc.
4) Template is an example of compile time polymorphism.

A. 1 and 2
B. 1, 2 and 3
C. 1, 2 and 4
D. 1, 2, 3 and 4
Answer» D. 1, 2, 3 and 4
52.

Which of the following is incorrect in C++?
(1)When we write overloaded function we must code the function for each usage.
(2)When we write function template we code the function only once.
(3)It is difficult to debug macros
(4)Templates are more efficient than macros

A. (1) and (2)
B. (1), (2) and (3)
C. (3) and (4)
D. All are correct.
Answer» D. All are correct.
53.

Pick the odd one out

A. array type
B. character type
C. Boolean type
D. integer type
Answer» A. array type
54.

Which data type is used to represent the absence of parameters?

A. int
B. short
C. void
D. float
Answer» C. void
55.

What does an escape code represent?

A. alert
B. backslash
C. tab
D. form feed
Answer» A. alert
56.

Which type is best suited to represent the logical values?

A. integer
B. Boolean
C. character
D. all of the mentioned
Answer» B. Boolean
57.

Identify the user-defined types from the following?

A. enumeration
B. classes
C. both enumeration and classes
D. int
Answer» C. both enumeration and classes
58.

Which of the following statements are true? int f (float)

A. f is a function taking an argument of type int and returning a floating point number
B. f is a function taking an argument of type float and returning an integer
C. f is a function of type float
D. none of the mentioned
Answer» B. f is a function taking an argument of type float and returning an integer
59.

The value 132.54 can be represented using which data type?

A. double
B. void
C. int
D. bool
Answer» A. double
60.

When a language has the capability to produce new data type mean, it can be called as …...

A. overloaded
B. extensible
C. encapsulated
D. reprehensible
Answer» B. extensible
61.

Choose the operator which cannot be overloaded.

A. /
B. ( )
C. ::
D. %
Answer» C. ::
62.

Which operator is required to be overloaded as member function only?

A. _
B. _ _
C. ++ (postfix version)
D. =
Answer» D. =
63.

Class function which is called automatically as soon as the object is created is called as __

A. Constructor
B. Destructor
C. Friend function
D. Inline function.
Answer» A. Constructor
64.

Which type of data file is analogous to an audio cassette tape?

A. Random access file
B. Sequential access file
C. Binary file
D. Source code file
Answer» B. Sequential access file
65.

What is the built in library function to compare two strings?

A. string_cmp()
B. strcmp()
C. equals()
D. str_compare()
Answer» B. strcmp()
66.

Which of the following are member dereferencing operators in CPP? 1. * 2. :: 3. ->* 4. ::* 5. ->

A. Only 1, 3, 4
B. Only 1 and 5
C. Only 3 and 4
D. Only 3,4,5
Answer» A. Only 1, 3, 4
67.

Which of the followings is/are pointer-to-member declarator?

A. ->*
B. .*
C. ::*
D. both A and B
Answer» C. ::*
68.

Assigning one or more function body to the same name is called ____________.

A. Function Overriding
B. Function Overloading
C. Both A and B
D. None of the above
Answer» B. Function Overloading
69.

Default values for a function are specified when ____.

A. Function is defined
B. Function is declared
C. Both a and b
D. None of these
Answer» B. Function is declared
70.

Which of the following best defines the syntax for template function?

A. Template
B. Template return_type Function_Name(Parameters)
C. Both a and b
D. None of these
Answer» C. Both a and b
71.

Return type of uncaught_exception () is ________________.

A. int
B. bool
C. char *
D. double
Answer» B. bool
72.

If inner catch handler is not able to handle the exception then__________.

A. Compiler will look for outer try handler
B. Program terminates abnormally
C. Compiler will check for appropriate catch handler of outer try block
D. None
Answer» C. Compiler will check for appropriate catch handler of outer try block
73.

Attempting to throw an exception that is not supported by a function call results in calling _____________ library function.

A. indeterminate ()
B. unutilized()
C. unexpected()
D. unpredicted()
Answer» C. unexpected()
74.

The code of statements which may cause abnormal termination of the program should be written under_________ block.

A. Try
B. catch
C. Finally
D. None of these
Answer» A. Try
75.

When a virtual function is redefined by the derived class, it is called___________.

A. Overloading
B. Overriding
C. Rewriting
D. All of these
Answer» B. Overriding
76.

While overloading binary operators using member function, it requires ___ argument/s.

A. Zero
B. One
C. Two
D. Three
Answer» B. One
77.

Where the default value of parameter have to be specified?

A. Function call
B. Function definition
C. Function prototype
D. Both B or C
Answer» C. Function prototype
78.

For automatic objects, constructors and destructors are called each time the objects

A. enter and leave scope
B. inherit parent class
C. are constructed
D. are destroyed
Answer» A. enter and leave scope
79.

Which operation is used as Logical 'AND'

A. Operator-&
B. Operator-
C. Operator-&&
D. Operator +
Answer» C. Operator-&&
80.

When an ADT is implemented as a C++ class, which of the following should normally be true?

A. Member functions are private, member variables are public
B. Member functions are public, member variables are private
C. Member functions as well as member variables are private
D. Member functions as well as member variables are public
Answer» B. Member functions are public, member variables are private
81.

Variable that are listed in function's calls are called

A. Actual parameter
B. Declared parameter
C. Passed parameter
D. None
Answer» B. Declared parameter
82.

What kind of error can arise when there is a problem with memory?

A. Segmentation fault
B. Produce an error
C. Both Segmentation fault & Produce an error
D. None of the mentioned
Answer» A. Segmentation fault
83.

Which operations don’t throw anything?

A. Operations which are reversible
B. Operations which are irreversible
C. Operations which are static
D. Operations which are dynamic
Answer» B. Operations which are irreversible
84.

What operation can be performed by destructor?

A. Abort the program
B. Resource cleanup
C. Exit from the current block
D. None of the mentioned
Answer» B. Resource cleanup
85.

Which interface in the container is required for storage management?

A. Memory management
B. Allocator interface
C. Memory interface
D. None of the mentioned
Answer» B. Allocator interface
86.

How can the member functions in the container be accessed?

A. Iterator
B. Indirect
C. Both Iterator & Indirect
D. None of the mentioned
Answer» A. Iterator
87.

In which type of storage location are the vector members stored?

A. Contiguous storage locations
B. Non-contiguous storage locations
C. Contiguous & Non-contiguous storage locations
D. None of the mentioned
Answer» A. Contiguous storage locations
88.

What do container adapter provide to interface?

A. Restricted interface
B. More interface
C. No interface
D. None
Answer» A. Restricted interface
89.

What does the sequence adaptor provide?

A. Insertion
B. Deletion
C. Interface to sequence container
D. None
Answer» C. Interface to sequence container
90.

Which operators is part of RTTI?

A. dynamic_cast()
B. typeid
C. Both dynamic_cast() & typeid
D. None
Answer» C. Both dynamic_cast() & typeid
91.

At which time does the static_cast can be applied?

A. Compile-time construct
B. Runtime construct
C. Both Compile-time & Runtime construct
D. None
Answer» A. Compile-time construct
92.

Which function is used to position back from the end of file object?

A. seekg
B. seekp
C. both seekg & seekp
D. None
Answer» A. seekg
93.

String class have a concat() function that is used to _____________________

A. Replace old string by new string
B. Add two strings
C. Append one string at end of another string
D. Remove a string from end of one string
Answer» C. Append one string at end of another string
94.

Which among the following is/are type(s) of this pointer?

A. const
B. volatile
C. const or volatile
D. int
Answer» C. const or volatile
95.

Which is the pointer which denotes the object calling the member function?

A. Variable pointer
B. This pointer
C. Null pointer
D. Zero pointer
Answer» B. This pointer
96.

Which property is shown most when upcasting is used?

A. Code reusability
B. Code efficiency
C. Complex code simple syntax
D. Encapsulation
Answer» C. Complex code simple syntax
97.

If multiple inheritance is implemented, which upcasting will be correct?

A. Upcast to first base class listed in inheritance
B. Upcast to any base class
C. Upcast to send base class listed in inheritance
D. Upcast is not possible
Answer» B. Upcast to any base class
98.

When are the pointer types known for upcasting the objects?

A. Compile time
B. Runtime
C. Source code build time
D. Doesn’t apply to pointer types
Answer» A. Compile time
99.

Which among the following is a mandatory condition for downcasting?

A. It must not be done explicitly
B. It must be done implicitly
C. It must be done explicitly
D. It can’t be done explicitly
Answer» C. It must be done explicitly
100.

Which container provides random access iterators?

A. vector
B. deque
C. sort
D. both vector & deque
Answer» D. both vector & deque

Done Studing? Take A Test.

Great job completing your study session! Now it's time to put your knowledge to the test. Challenge yourself, see how much you've learned, and identify areas for improvement. Don’t worry, this is all part of the journey to mastery. Ready for the next step? Take a quiz to solidify what you've just studied.