C++ Programming MCQ (Multiple Choice Questions) - SchoolingAxis

C++ Programming MCQ (Multiple Choice Questions)

 Que- How to handle error in the destructor? 

a. throwing 

b. terminate 

c. both throwing & terminate 

d. try 


Answer- terminate 


Que- What kind of exceptions are available in c++? 

a. handled 

b. unhandled 

c. static 

d. dynamic 


Answer- unhandled 


Que- What is meant by exception specification? 

a. A function is limited to throwing only a specified list of exceptions 

b. A catch can catch all types of exceptions 

c. A function can throw any type of exceptions 

d. A try can catch all types of exceptions 


Answer- A function is limited to throwing only a specified list of exceptions 


Que- Identify the correct statement about throw(type). 

a. A function can throw any type of exceptions 

b. A function can throw an exception of certain type only 

c. A function can't throw any type of exception 

d. A function can catch all types of exceptions 


Answer- A function can throw an exception of certain type only 


Que- What will happen when a programs throws any other type of exception other than specified? 

a. terminate 

b. arise an error 

c. run 

d. throw 


Answer- arise an error 


Que- What do you mean by "No exception specification"? 

a. It throws nothing 

b. It can throw anything 

c. It can catch anything 

d. It can try anything 


Answer- It can throw anything 


Que- 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- Operations which are irreversible 


Que- What will happen when we move to try block far away from catch block? 

a. Reduces the amount of code in cache 

b. Increases the amount of code in cache 

c. Don't alter anything 

d. Increases the amount of code 


Answer- Reduces the amount of code in cache 


Que- What will happen if an exception that is thrown may cause a whole load of objects to go out of scope? 

a. Terminate the program 

b. Produce a runtime error 

c. It will be added to the overhead 

d. Compilation error 


Answer- It will be added to the overhead 


Que- What operation can be performed by destructor? 

a. Abort the program 

b. Resource cleanup 

c. Exit from the current block 

d. Terminate the program 


Answer- Resource cleanup 


Que- What is the main purpose of the constructor? 

a. Begin the execution of class 

b. Include the macros for the program 

c. Establish the class invariant 

d. Terminate the program 


Answer- Establish the class invariant 


Que- Why is it expensive to use objects for the exception? 

a. Exception object is created only if an error actually happens 

b. Because of execution time 

c. Memory space involved in creating an exception object 

d. Because of time and space 


Answer- Exception object is created only if an error actually happens 


Que- What is an exception in C++ program? 

a. A problem that arises during the execution of a program 

b. A problem that arises during compilation 

c. Also known as the syntax error 

d. Also known as semantic error 


Answer- A problem that arises during the execution of a program 


Que- By default, what a program does when it detects an exception? 

a. Continue running 

b. Results in the termination of the program 

c. Calls other functions of the program 

d. Removes the exception and tells the programmer about an exception 


Answer- Results in the termination of the program 


Que- Why do we need to handle exceptions? 

a. To avoid unexpected behaviour of a program during run-time 

b. To let compiler remove all exceptions by itself 

c. To successfully compile the program 

d. To get correct output 


Answer- To avoid unexpected behaviour of a program during run-time 


Que- How Exception handling is implemented in the C++ program? 

a. Using Exception keyword 

b. Using try-catch block 

c. Using Exception block 

d. Using Error handling schedules 


Answer- Using try-catch block 


Que- Which part of the try-catch block is always fully executed? 

a. try part 

b. catch part 

c. finally part 

d. throw part 


Answer- finally part 


Que- Which of the following is an exception in C++? 

a. Divide by zero 

b. Semicolon not written 

c. Variable not declared 

d. An expression is wrongly written 


Answer- Divide by zero 


Que- What is an error in C++? 

a. Violation of syntactic and semantic rules of a languages 

b. Missing of Semicolon 

c. Missing of double quotes 

d. Violation of program interface 


Answer- Violation of syntactic and semantic rules of a languages 


Que- What is the difference between error and exception? 

a. Both are the same 

b. Errors can be handled at the run-time but the exceptions cannot 

c. Exceptions can be handled at the run-time but the errors cannot 

d. Both can be handled during run-time 


Answer- Exceptions can be handled at the run-time but the errors cannot 


Que- What are the different types of exceptions? 

a. 1 

b. 2 

c. 3 

d. 4 


Answer- 2 


Que- Which keyword is used to throw an exception? 

a. try 

b. throw 

c. throws 

d. except 


Answer- throw 


Que- What is Re-throwing an exception means in C++? 

a. An exception that is thrown again as it is not handled by that catching block 

b. An exception that is caught twice 

c. An exception that is not handled in one caught hence thrown again 

d. All of the mentioned 


Answer- All of the mentioned 


Que- Where should we place catch block of the derived class in a try-catch block? 

a. Before the catch block of Base class 

b. After the catch block of Base class 

c. Anywhere in the sequence of catch blocks 

d. After all the catch blocks 


Answer- Before the catch block of Base class 


Que- What id the syntax for catching any type of exceptions? 

a. catch(Exception e) 

b. catch(…) 

c. catch(Exception ALL) 

d. catch(ALL) 


Answer- catch(…) 


Que- Uncaught exception leads to ______________ 

a. termination of program 

b. successful execution of programs 

c. no effect on the program 

d. execution of other functions of the program starts 


Answer- termination of program 


Que- An uncaught handler returns to _______________ 

a. main function 

b. its caller 

c. its callee 

d. waits there for some time 


Answer- its callee 


Que- Header file used for exception handling in C++? 

a. <cstdlib> 

b. <string> 

c. <handler> 

d. <exception> 


Answer- <exception> 


Que- The C++ code which causes abnormal termination/behaviour of a program should be written under _________ block. 

a. try 

b. catch 

c. finally 

d. throw 


Answer- try 


Que- Exception handlers are declared with ____________ keyword. 

a. try 

b. catch 

c. throw 

d. finally 


Answer- catch 


Que- In nested try-catch block, if the inner catch block gets executed, then______________ 

a. Program stops immediately 

b. Outer catch block also executes 

c. Compiler jumps to the outer catch block and executes remaining statements of the main() function 

d. Compiler executes remaining statements of outer try-catch block and then the main() function 


Answer- Compiler executes remaining statements of outer try-catch block and then the main() function 


Que- If inner catch block is unable to handle the exception thrown then__________ 

a. The compiler looks for the outer try-catch block 

b. Program stops abnormally 

c. The compiler will check for appropriate catch handler of the outer try block 

d. The compiler will not check for appropriate catch handler of the outer try block 


Answer- The compiler will check for appropriate catch handler of the outer try block 


Que- In nested try catch blocks, if both inner and outer catch blocks are unable to handle the exception thrown, then ______________ 

a. Compiler executes only main() 

b. Compiler throws compile time errors about it 

c. Program will run without any interrupt 

d. Program will be termianted abnormally 


Answer- Program will be termianted abnormally 


Que- Which function is invoked when an unhandled exception is thrown? 

a. stop() 

b. aborted() 

c. terminate() 

d. abandon() 


Answer- terminate() 


Que- How one can restrict a function to throw particular exceptions only? 

a. By defining multiple try-catch blocks inside a function 

b. By defining a generic function within a try-catch block 

c. By defining a function with throw clauses 

d. Not allowed in C++ 


Answer- By defining a function with throw clauses 


Que- Which function is invoked when we try to throw an exception that is not supported by a function? 

a. indeterminate() 

b. unutilized() 

c. unexpected() 

d. unpredicted() 


Answer- unexpected() 


Que- Return type of uncaught_exception() is________________ 

a. int 

b. bool 

c. char * 

d. double 


Answer- bool 


Que- Which alternative can replace the throw statement? 

a. for 

b. break 

c. return 

d. exit 


Answer- return 


Que- What are the disadvantages if use return keyword to return error codes? 

a. You have to handle all exceptional cases explicitly 

b. Your code size increases dramatically 

c. The code becomes more difficult to read 

d. All of the mentioned 


Answer- All of the mentioned 


Que- What is most suitable for returning the logical errors in the program? 

a. Use constructor and destructor 

b. Set a global error indicator 

c. Use break keyword 

d. Use final keyword 


Answer- Set a global error indicator 


Que- What is the use of RAII in c++ programming? 

a. Improve the exception safety 

b. Terminate the program 

c. Exit from the block 

d. Crash the compiler 


Answer- Improve the exception safety 


Que- How many levels are there in exception safety? 

a. 1 

b. 2 

c. 3 

d. 4 


Answer- 3 


Que- Pick out the correct statement for error handling alternatives. 

a. Terminate the program 

b. Use the stack 

c. Exit from the block 

d. Use the queue 


Answer- Use the stack 


Que- What will happen when an exception is not processed? 

a. It will eat up a lot of memory and program size 

b. Terminate the program 

c. Crash the compiler 

d. Displays proper output 


Answer- It will eat up a lot of memory and program size 


Que- Which header file is used to declare the standard exception? 

a. #include<exception> 

b. #include<except> 

c. #include<error> 

d. #include<exce> 


Answer- #include<exception> 


Que- Where are standard exception classes grouped? 

a. namespace std 

b. error 

c. catch 

d. final 


Answer- namespace std 


Que- How many types of standard exception are there in c++? 

a. 9 

b. 5 

c. 6 

d. 7 


Answer- 9 


Que- Which of the following is best to include under try block? 

a. static values 

b. const values 

c. dynamic allocations 

d. default values 


Answer- dynamic allocations 


Que- What are the predefined exceptions in c++? 

a. Memory allocation errors 

b. I/O errors 

c. Both Memory allocation errors & I/O errors 

d. static errors 


Answer- Both Memory allocation errors & I/O errors 


Que- What will happen when introduce the interface of classes in a run-time polymorphic hierarchy? 

a. Separation of interface from implementation 

b. Merging of interface from implementation 

c. Separation of interface from debugging 

d. Merging of interface from debugging 


Answer- Separation of interface from implementation 


Que- Which classes are called as mixin? 

a. Represent a secondary design 

b. Classes express functionality which represents responsibilities 

c. Standard logging stream 

d. Represent a priary design 


Answer- Classes express functionality which represents responsibilities 


Que- What is the use of clog? 

a. Standard logging stream 

b. Error stream 

c. Input stream 

d. output stream 


Answer- Standard logging stream 


Que- How many types of guarantees are there in exception class can have? 

a. 1 

b. 2 

c. 3 

d. 4 


Answer- 3 


Que- Which operator is used to create the user-defined streams in c++? 

a. >> 

b. << 

c. & 

d. Both >> & << 


Answer- Both >> & << 


Que- What does the cerr represent? 

a. Standard error stream 

b. Standard logging stream 

c. Input stream 

d. Output stream 


Answer- Standard error stream 


Que- What is meant by multiple inheritance? 

a. Deriving a base class from derived class 

b. Deriving a derived class from base class 

c. Deriving a derived class from more than one base class 

d. Deriving a derived base class 


Answer- Deriving a derived class from more than one base class 


Que- Which symbol is used to create multiple inheritances? 

a. Dot 

b. Comma 

c. Dollar 

d. star 


Answer- Comma 


Que- Which of the following advantages we lose by using multiple inheritances? 

a. Dynamic binding 

b. Polymorphism 

c. Both Dynamic binding & Polymorphism 

d. Constructor 


Answer- Both Dynamic binding & Polymorphism 


Que- Which design patterns benefit from the multiple inheritances? 

a. Adapter and observer pattern 

b. Code pattern 

c. Glue pattern 

d. Star pattern 


Answer- Adapter and observer pattern 


Que- What are the things are inherited from the base class? 

a. Constructor and its destructor 

b. Operator=() members 

c. Friends 

d. All of the mentioned 


Answer- All of the mentioned 


Que- What is Inheritance in C++? 

a. Wrapping of data into a single class 

b. Deriving new classes from existing classes 

c. Overloading of classes 

d. Classes with same names 


Answer- Deriving new classes from existing classes 


Que- How many specifiers are used to derive a class? 

a. 1 

b. 2 

c. 3 

d. 4 


Answer- 3 


Que- Which specifier makes all the data members and functions of base class inaccessible by the derived class? 

a. private 

b. protected 

c. public 

d. both private and protected 


Answer- private 


Que- If a class is derived privately from a base class then ______________________________ 

a. no members of the base class is inherited 

b. all members are accessible by the derived class 

c. all the members are inherited by the class but are hidden and cannot be accessible 

d. no derivation of the class gives an error 


Answer- all the members are inherited by the class but are hidden and cannot be accessible 

Previous Post Next Post

Responsive Ad