Test Series - cpp

Test Number 51/102

Q: Pick out the correct answer.
A. Exceptions are not suitable for critical points in code
B. Exception are suitable for critical points in code
C. Exceptions are used when postconditions of a function cannot be satisfied
D. Throw block should be placed after try block
Solution: If there is many number of exceptions in the program means, We have to use multiple catch statement and it is hard to keep track of the program.
Q: When exceptions are used?
A. To preserve the program
B. Exceptions are used when postconditions of a function cannot be satisfied
C. Exceptions are used when postconditions of a function can be satisfied
D.  Exceptions are used when preconditions of a function cannot be satisfied
Solution: Exceptions are used when postconditions of a function can be satisfied.
Q: How many parameters does the throw expression can have?
A. 1
B. 2
C. 3
D. 4
Solution: In c++ program, We can be able to throw only one error at a time.
Q: Where exception are handled?
A. inside the program
B. outside the regular code
C. both inside or outside
D. main program
Solution: Exception are handled outside the regular code.
Q: Which is used to check the error in the block?
A. try
B. throw
C. catch
D. handler
Solution: The try block is used to check for errors, if there is any error means, it can throw it to catch block.
Q: How to handle the exception in constructor?
A. We have to throw an exception
B. We have to return the exception
C. We have to throw an exception & return the exception
D. We have to catch an exception
Solution: As a constructor don’t have a return type, We have to throw the exception.
Q: What should present when throwing a object?
A. constructor
B. copy-constructor
C. destructor
D. copy-destructor
Solution: copy-constructor is mandatory for throwing a object.
Q: What can go wrong in resource management on c++?
A. Leakage
B. Exhaustion
C. Dangling
D. Exception
Solution: If there is any mishap in memory or resource management means, the problems that are mentioned above can happen.
Q: When do we call that resource is leaked?
A. Arise of compile time error
B. It cannot be accessed by any standard mean
C. Arise of runtime error
D. It can be accessed by any standard mean
Solution: Resource is said to be leaked when it cannot be accessed by any means of standard mean.
Q: 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. runtime error
Solution: segmentation fault error can arise when there is a problem with memory.

You Have Score    /10