+ All Categories
Home > Documents > kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try...

kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try...

Date post: 16-Feb-2019
Category:
Upload: doxuyen
View: 242 times
Download: 1 times
Share this document with a friend
54
Id 1 Questio n What is meaning of template parameter? A It is used to pass a type as argument B Used to evaluate a type C It can of no return type D None of the mentioned Answer A Marks 1 Unit IV Id 2 Questio n ______Keyword is used in template. A Class B Typename C Both a and b D Using Answer C Marks 1 Unit IV Id 3 Questio n What is scope of template parameter? A Inside a block only B Inside the class only C Throughout program D All of the above Answer A Marks 1 Unit IV Id 4 Questio n Function overloading is also similar to which of the following A Operator overloading B Destructor overloading
Transcript
Page 1: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

Id 1Question What is meaning of template parameter?A It is used to pass a type as argumentB Used to evaluate a typeC It can of no return typeD None of the mentionedAnswer AMarks 1Unit IV

Id 2Question ______Keyword is used in template.A ClassB TypenameC Both a and bD UsingAnswer CMarks 1Unit IV

Id 3Question What is scope of template parameter?A Inside a block onlyB Inside the class onlyC Throughout programD All of the aboveAnswer AMarks 1Unit IV

Id 4Question Function overloading is also similar to which of the followingA Operator overloadingB Destructor overloadingC Constructor overloadingD Virtual functionAnswer BMarks 1Unit IV

Id 5Question Generic programming is approach of______________________which are applicable for

all typesA Generalised algorithmB Pseude algorithm

Page 2: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

C Both a and bD None of the aboveAnswer AMarks 1Unit IV

Id 6Question Template are of typesA Function templateB Class templateC Both a and bD None of the aboveAnswer CMarks 1Unit IV

Id 7Question Class template can be created using________syntax.A Template<class T>class classnameB Template<class T1,class T2> class classnameC Both a and bD None of the above mentionedAnswer CMarks 1Unit IV

Id 8Question Syntax for creating a function template isA Template<typename t>returntype function nameB Template<class T> returntype function nameC Both a and bD None of the above mentionedAnswer CMarks 1Unit IV

Id 9Question Pick up the correct statement

i)template allow us to define generic classes and functionsii)template support generic programmingiii)function template overloading is possible

A i onlyB i and ii onlyC ii and iii onlyD i, ii and iiiAnswer D

Page 3: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

Marks 1Unit IV

Id 10Question Template function can be overloadedA TrueB FalseCDAnswer AMarks 1Unit IV

Id 11Question Why we use :: template-template parameter?A bindingB rebindingC both a &bD none of theseAnswer CMarks 1Unit IV

Id 12Question Which of the things does not require instantiation?A functionsB non virtual member functionC member classD all of the mentionedAnswer DMarks 1Unit IV

Id 13Question A template provides a convenient way to make a family ofA variables.B functionsC classesD B and CAnswer DMarks 1Unit IV

Id 14Question Templates automatically create different versions of a function, depending on user input.A TRUE

Page 4: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

B FALSECDAnswer BMarks 1Unit IV

Id 15Question A template classA is designed to be stored in different containers.B works with different data types.C generates objects which must all be identical.D generates classes with different numbers of member functions.Answer BMarks 1Unit IV

Id 16Question There can be more than one template argument.A TRUEB FALSECDAnswer AMarks 1Unit IV

Id 17Question Actual code for a template function is generated whenA the function declaration appears in the source code.B the function definition appears in the source code.C a call to the function appears in the source code.D the function is executed at runtime.Answer CMarks 1Unit IV

Id 18Question An exception is typically caused byA the programmer who writes an application’s code.B the creator of a class who writes the class member functions.C a runtime error.D an operating system malfunction that terminates the program.Answer CMarks 1Unit IV

Page 5: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

Id 19Question Statements that might cause an exception must be part of a catch block.A TRUEB FALSECDAnswer BMarks 1Unit IV

Id 20Question Exceptions are thrownA from the catch block to the try block.B from a throw statement to the try block.C from the point of the error to a catch block.D from a throw statement to a catch block.Answer DMarks 1Unit IV

Id 21Question A statement that throws an exception does not need to be located in a try block.A TRUEB FALSECDAnswer BMarks 1Unit IV

Id 22Question The following is/are errors for which an exception would typically be thrown:A An excessive amount of data threatens to overflow an array.B new cannot obtain the requested memory.C A power failure shuts down the system.D A and BAnswer DMarks 1Unit IV

Id 23Question Additional information sent when an exception is thrown may be placed inA the throw keyword.B the function that caused the error.C the catch block.

Page 6: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

D an object of the exception class.Answer DMarks 1Unit IV

Id 24Question A program can continue to operate after an exception has occurred.A TRUEB FALSECDAnswer AMarks 1Unit IV

Id 25Question What is the output of following program?

#include <iostream>using namespace std;int main(){int x = -1;try {

cout <<"Inside try \n";if (x <0){

throw x;cout <<"After throw \n";

}}catch (int x ) {

cout <<"Exception Caught \n";}

cout <<"After catch \n";return 0;}

A Inside tryException CaughtAfter throwAfter catch

B Inside tryException CaughtAfter catch

C Inside try

Page 7: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

Exception CaughtD Inside try

After throwAfter catch

Answer BMarks 2Unit IV

Id 26Question What is the advantage of exception handling?

1) Remove error-handling code from the software's main line of code.2) A method writer can chose to handle certain exceptions and delegate others to the caller.3) An exception that occurs in a function can be handled anywhere in the function call stack.

A Only 1B 1, 2 and 3C 1 and 3D 1 and 2Answer BMarks 2Unit IV

Id 27Question What should be put in a try block?

1. Statements that might cause exceptions2. Statements that should be skipped in case of an exception

A Only 1B Only 2C Both 1 and 2D None of the aboveAnswer CMarks 1Unit IV

Id 28Question What is the output of following program

#include<iostream>using namespace std; class Base {};class Derived: public Base {};int main(){ Derived d;

Page 8: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

try { throw d; } catch(Base b) { cout<<"Caught Base Exception"; } catch(Derived d) { cout<<"Caught Derived Exception"; } return 0;}

A Caught Derived ExceptionB Caught Base ExceptionC Caught Derived Exception

Caught Base ExceptionD Compiler ErrorAnswer BMarks 1Unit IV

Id 29Question What is the output of following program?

#include <iostream>using namespace std; int main(){ try { throw 10; } catch (...) { cout <<"default exception\n"; } catch (int param) { cout <<"int exception\n"; } return 0;}

A default exceptionB int exceptionC default exception

Page 9: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

int exceptionD Compiler ErrorAnswer DMarks 1Unit IV

Id 30Question What is the output of following program?

#include <iostream>using namespace std; class Test {public: Test() { cout <<"Constructing an object of Test "<<endl; } ~Test() { cout <<"Destructing an object of Test " <<endl; }}; int main() { try { Test t1; throw 10; } catch(int i) { cout <<"Caught "<<i <<endl; }}

A Caught 10B Constructing an object of Test

Caught 10C Constructing an object of Test

Destructing an object of TestCaught 10

D Compiler ErrrorAnswer CMarks 2Unit IV

Id 31Question What happens in C++ when an exception is thrown and not caught anywhere like

following program?

#include <iostream>using namespace std; int fun() throw (int){

Page 10: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

throw 10;} int main() { fun(); return 0;}

A Compiler errorB Abnormal program terminationC Program doesn't print anything and terminates normallyD None of the aboveAnswer BMarks 1Unit IV

Id 32Question Which alternative can replace the throw statement ?A ExitB ForC BreakD ReturnAnswer DMarks 1Unit IV

Id 33Question Which of the following keyword can not be appered inside the class?A VirtualB StaticC TemplateD FriendAnswer CMarks 1Unit IV

Id 34Question What is template?A Template is formula for creating a generic classB Template is used to manipulate classC Template is used for creating functionsD None of theseAnswer AMarks 1Unit IV

Id 35

Page 11: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

Question Select the correct syntax of template:A TemplateB Template<>C TempD None of theseAnswer BMarks 1Unit IV

Id 36Question A class is generated from template class is called _______.A inherited classB derived classC generated classD subclassAnswer CMarks 1Unit II

Id 37Question ________ is useful when template of template is used?A Friend functionB Static functionC TypedefD InheritanceAnswer CMarks 1Unit IV

Id 38Question Which of the C++ feature allows you to create classes that are dynamic for using data

types?A TemplatesB InheritanceC PolymorphismD Information hidingAnswer AMarks 1Unit IV

Id 39Question A function template means _______.A creating a function having exact typeB creating a function without having to specify exact typeC both a and bD none of these

Page 12: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

Answer BMarks 1Unit IV

Id 40Question Which of the following is used to describe the function using placeholder type?A Template type parameterB Template parameterC Template typeD None of theseAnswer AMarks 1Unit IV

Id 41Question String template is used _____.A to replace a string.B to replace a string with another stringC to delete a stringD none of theseAnswer BMarks 1Unit IV

Id 42Question Maximum number of template argument in function template is _______.A twoB threeC fourD manyAnswer DMarks 1Unit IV

Id 43Question Template function must haveA one or more than one argumentB zero argumentC only one argumentD at least two argumentsAnswer AMarks 1Unit IV

Id 44Question Template function must have at least ________ generic data type.

Page 13: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

A zeroB oneC twoD none of theseAnswer BMarks 1Unit IV

Id 45Question Templates provide way of abstracting ______ information.A typeB dataC methodD accessAnswer AMarks 1Unit IV

Id 46Question If you create instantiation of a class template with an int and then create a second

instantiation with a double thenA once the function is used for one data type it becomes unavailable for other typeB you can not perform this kind of operation in C++C you must precede each function call with the word int or doubleD none of theseAnswer CMarks 1Unit IV

Id 47Question If templates were removed from C++,Which of the following will be true?

I. Some algorithms could no longer be implementedII. Any particular algorithms could still be implemented but often less elegantly.

A Only I is trueB Only II is trueC Both I and II is trueD None of theseAnswer DMarks 1Unit 4

Id 48Question In the template <class T>declaration of T stands for ________.A integer data typeB arbitary classC generic data types

Page 14: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

D none of theseAnswer CMarks 1Unit IV

Id 49Question What is the meaning of template parameter?A It is used to pass a type as argumentB It is used to evalute a typeC It has no return typeD None of theseAnswer AMarks 1Unit IV

Id 50Question What can be passed by non-type template parameter during compile time?A IntB DoubleC CharD constant expressionAnswer DMarks 1Unit IV

Id 51Question Choose the correct statement from the following:A Template function will take long time to executeB Template functions are written when you want to have only one code for many different

typesC due to template function the duplicate code will get increasedD None of theseAnswer BMarks 1Unit IV

Id 52Question How many types of templates are there in c++?A TwoB ThreeC FourD None Of TheseAnswer AMarks 1Unit IV

Page 15: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

Id 53Question What is the task of compiler while handling template?A type associationB PortabilityC code eliminationD all of the aboveAnswer CMarks 1Unit IV

Id 54Question What should be the name of the parameter that the template should take?A same as classB same as functionC same as templateD none of theseAnswer CMarks 1Unit IV

Id 55Question Which keyword can be used with template?A TypenameB operatorC both a and bD None of theseAnswer AMarks 1Unit IV

Id 56Question Which of the following describes a difference between template function and

template class in c++?A The compiler determines the type of a template function's arguments, but

the types of template classes must be stated explicitly when declaring objectsB template functions cannot be defined for user-defined types, but template classes canC template classes cannot be defined for user-defined types,but

templatefunctions can.D None Of TheseAnswer AMarks 1Unit IV

Id 57Question What is the validity of templet parameter?A Inside the class

Page 16: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

B Inside the blockC whole programD None of theseAnswer BMarks 1Unit IV

Id 58Question Which of the following does not required installation ?A Non virtual member functionB Member classC FunctionD All of aboveAnswer DMarks 1Unit IV

Id 59Question Which keyword is used to handle the exception ?A TryB CatchC ThrowD ExceptionAnswer BMarks 1Unit IV

Id 60Question What is the use of the keyword finally ?A It is used at the start of the program for handling all the exceptionsB It is used at the end of the program to handle all the exceptionsC It can be used anywhere in the program to handle all the exceptionsD None of theseAnswer BMarks 1Unit IV

Id 61Question Which of the following most preferred way of throwing and handling exception?A Throw by value and catch by referenceB Throw by reference and catch by valueC Throw by value and catch by valueD None of theseAnswer AMarks 1Unit IV

Page 17: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

Id 62Question Which of the following is the most general exception handler that catches exception of

any type?A Catch(std::exception)B Catch(std:any_exception)C Catch(...)D Catch()Answer CMarks 1Unit IV

Id 63Question Which of the following causes an exceptionA Missing parenthesis in main()B Calling a function which is not presentC A syntax error D a run time error

Answer DMarks 1Unit IV

Id 64Question Which block should be placed after try block ?A ThrowB Catch C both a or bD none of theseAnswer CMarks 1Unit IV

Id 65Question Choose the correct statementA Exception are not suitable for critical points in the programB Exception are suitable for critical points in the programC Both a&bD None of theseAnswer AMarks 1Unit IV

Id 66Question In C++ program handling, a try block must be followed by _____catch blocksA exactly one

Page 18: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

B one or moreC exactly twoD none of theseAnswer BMarks 1Unit IV

Id 67Question The process of handling the actual exception occurs _________A inside the programB outside the programC both a &bD none of theseAnswer BMarks 1Unit IV

Id 68Question Which of the following is used to check the error in the block?A TryB ThrowC CatchD None of theseAnswer AMarks 1Unit IV

Id 69Question What should be present when throwing object ?A ConstructorB DestructorC copy constructorD none of theseAnswer CMarks 1Unit IV

Id 70Question For handling the exception in C++ _______ are usedA catch handlers

B exception handlersC PointersD none of theseAnswer BMarks 1

Page 19: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

Unit IV

Id 71Question For handling the exceptions in C++ _________ is used .A handler functionB terminate functionC both a &bD none of theseAnswer BMarks 1Unit IV

Id 72Question How many parameters does the throw expression can have ?A 0B 1C 2D 3Answer BMarks 1Unit IV

Id 73Question What kind of exceptions are used in C++A HandledB UnhandledC StaticD DynamicAnswer BMarks 1Unit IV

Id 74Question What will happen when exception is uncaught?A Arise an errorB program will runC execute in a loopD none of theseAnswer AMarks 1Unit IV

Id 75Question Choose the correct statementA A function can throw any type of exception

Page 20: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

B a function can throw an exception of certain type onlyC A exception can't throw any type of exceptionD none of theseAnswer BMarks 1Unit 4

Id 76Question What fuunction will be called when we have uncaught exception?A CatchB ThrowC TerminateD none of theseAnswer CMarks 1Unit IV

Id 77Question What will happen when a programs throws any other of exception other than specified ?A still executeB TerminateC raise an errorD none of these.Answer CMarks 1Unit IV

Id 78Question Which statement is used to catch all types of exceptions?A catch()B catch(Test t)C catchD none of theseAnswer DMarks 1Unit IV

Id 79Question Which keyword can be used as a templateA ExceptionB TypenameC both a & bD FunctionAnswer BMarks 1Unit IV

Page 21: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

Id 80Question An Exception is thrown using _____________keyword in cppA ThrowsB ThrowC ThrewD ThrownAnswer BMarks 1Unit IV

Id 81Question Which parameter is legal for non-type template?A pointer to memberB objectC classD none of theseAnswer AMarks 1Unit IV

Id 82Question Which of the things does not require instantiation?A functionsB Non virtual member functionC member classD all of theseAnswer DMarks 1Unit IV

Id 83Question Which of the following permits function overloading on c++?A Data TypeB Number of argumentsC A &B bothD none of theseAnswer CMarks 1Unit IV

Id 84Question Function overloading is also similar to which of the following?A Operator OverloadingB Constructer overloadingC Destructor overloading

Page 22: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

D none of the aboveAnswer BMarks 1Unit IV

Id 85Question Which is dependent on template parameterA base classB abstract classC methodD none of the aboveAnswer AMarks 1Unit IV

Id 87Question How to declare a template?A TemB TempC Template<>D none of theseAnswer CMarks 1Unit IV

Id 88Question What may be the name of parameter that the template should take?A same as templateB same as classC same as functionD none of theseAnswer AMarks 1Unit IV

Id 89Question Which is used to handle the exceptions in c++?A catch handlerB handlerC exception handlerD all of theseAnswer BMarks 1Unit IV

Id 90

Page 23: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

Question Which is called on allocating the memory for array of objects?A Function B MethodC DestructorD ConstructorAnswer DMarks 1Unit IV

Id 91Question Which value is placed in the base class?A Inherited valueB Derived valueC Default type valuesD Both a and bAnswer CMarks IVUnit IV

Id 92Question Which is used to get the input during runtime?A coutB cinC TemplateD All of the aboveAnswer BMarks 1Unit IV

Id 93Question __________is used to perform the generic programming.A ClassB TemplateC Function D InheritanceAnswer All of the aboveMarks BUnit IV

Id 94Question A template can be considered as a kind of macrosA TrueB FalseCDAnswer A

Page 24: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

Marks 1Unit IV

Id 95Question We can not define more than 2 placeholder in class/function template.A FalseB TrueCDAnswer AMarks 1Unit IV

Id 96Question When template is defined with parameter that would be replaced by specified _______at

the time of actual use of class or function.A KeywordB OperatorC DatatypeD None of the above mentionedAnswer CMarks IVUnit IV

Id 97Question Templates sometimes called as ___________A Parameterized classesB Parameterized functionC Both a and bD None of the above mentionedAnswer CMarks 1Unit IV

Id 98Question Exceptions are of typeA SynchronousB AsynchronousC Both a and bD None of the above mentionedAnswer CMarks 1Unit IV

Id 99Question “out-of-range”, “overflow” are the type of exceptions

Page 25: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

A AsynchronousB SynchronousC DefaultD None of the aboveAnswer BMarks 1Unit IV

Id 100Question The most type of error--------.A Logical errorB Syntactic errorC Both a and bD Class Answer CMarks 1Unit IV

Id 101Question Run time error is known as ______A Logical errorB Syntactic errorC ExceptionD All of the above mentionedAnswer CMarks 1Unit IV

Id 102Question How the exception is throwA throw exceptionB throw(exception)C throwD All of the aboveAnswer DMarks 1Unit IV

Id 103Question Can we throw exception more than one timeA TrueB FalseCDAnswer AMarks 1

Page 26: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

Unit IV

Id 104Question Which statement we have to use rethrowing exceptionA throw(exception)B ThrowC Both a and bD None of the above mentionedAnswer BMarks 1Unit IV

Id 105Question Exception can be handle if_______A Throwing argument is match with catch blockB Throwing argument is not match with catch blockC Exception is not thrownD None of the abveAnswer AMarks 1Unit IV

Id 106Question With this concept same algorithm can be used for different data typesA Procedure oriented paradigmB Generic programmingC Both a and bD None of the aboveAnswer BMarks 1Unit IV

Id 106Question Template is a way creating generalize functions and classes which are applicable for all

data types A FalseB TrueCDAnswer BMarks 1Unit IV

Id 107Question Class template is applicable for ___.A For function only

Page 27: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

B For that class onlyC Both a and bD None of the above mentionedAnswer BMarks 1Unit IV

Id 108Question Function template is applicable for_________.A For function onlyB For that class onlyC Both a and bD None of the above mentionedAnswer AMarks 1Unit IV

Id 109Question How many kinds of parameters are there in c++A 1B 2C 3D 4Answer CMarks 1Unit IV

Id 110Question Which type of program is recommended to include in try blockA Static memory allocationB Dynamic memory allocationC Const referenceD PointerAnswer BMarks 1Unit IV

Id 111Question How to handle error in destructorA ThrowingB TerminateC Both a and bD None of the mentionedAnswer BMarks 1Unit IV

Page 28: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

Id 112Question In catch statement we have multiple parametersA YesB NoCDAnswer BMarks 1Unit IV

Id 113Question ------kind of exceptions are in c++.A HandledB StaticC Both a and bD UnhandledAnswer AMarks 1Unit IV

Id 114Question Pick up the correct statementA To throw exception we have to use catch statementB Error occurring code is placed in try block C We can not have multiple throwing mechanism in c++D Both and bAnswer BMarks 1Unit IV

Id 115Question Can we used constructor for exception handlingA Yes B NoCDAnswer AMarks 1Unit IV

Id 116Question Class template can be overloadedA TrueB FalseC

Page 29: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

DAnswer BMarks 1Unit IV

Id 117Question ______is a generic class handlerA Catch(---)B Catch(-,-)C Catch(…)D Catch(void)Answer CMarks 1Unit IV

Id 118Question If the exception is not handled then which standard library function get invokedA stop()B terminate()C Read()D Write()Answer BMarks 1Unit IV

Id 119Question Exception can be only built in typeA TrueB FalseCDAnswer AMarks 1Unit IV

Id 120Question What will be output of program

#include<iostream>using namespace std;template<class T>T display(T x){cout<< “using template x=”<<x<<“\n”;}int display(int x){

Page 30: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

cout<<“Normal display x=”<<x <<“\n”;}int main(){display(2.3);display(3);diplay(1.1);}

A Normal display x=2.3Using template x=3Normal display x=1.1

B using template x=2.3Normal display x=3using template x=1.1

C using template x=3Normal display x=2.3using template x=1.1

D None of the aboveAnswer BMarks 2Unit IV

Id 121Question In nested try blocks, there is no need to specify catch handler for inner try block. Outer

catch handler is sufficient for the programA TrueB FalseCDAnswer BMarks 1Unit IV

Id 122Question Can we write try block within try blockA TrueB FalseCDAnswer AMarks 1Unit IV

Id 123Question Can we prevent a function from throwing any exceptionsA Yes

Page 31: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

B NoCDAnswer AMarks 1Unit IV

Id 124Question What is return type of uncaught_exception() is----A Char*B DoubleC Int D BoolAnswer DMarks 1Unit IV

Id 125Question Can we write a throw statement inside catch statementA YesB NoCDAnswer AMarks 1Unit IV

Id 126Question We can define our own exceptions in c++A FalseB TrueCDAnswer BMarks 1Unit IV

Id 127Question Stack unwinding deals with A PolymorphismB inheritanceC Exception handlingD ClassesAnswer CMarks 1Unit IV

Page 32: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

Id 128Question What is STLA Standard Term LibraryB Standard Tree LibraryC Standard Template LibraryD None of the above mentionedAnswer CMarks 1Unit IV

Id 129Question Pick up the correct statement

• Catch statement be placed immediately after try block• It can have multiple parameters• There must be multiple catch handler for a try block• Generic catch statement we can placed anywhere in program

A i and iiB i and iiiC i and ivD i , ii and iiiAnswer BMarks 2Unit IV

Id 130Question Generic catch should be placed atA End of all statementB Before tryC Before throwD Inside tryAnswer AMarks 1Unit IV

Id 131Question Irrespective of exception occurrence, catch handler will be always executedA YesB NoCDAnswer BMarks 1Unit IV

Id 132

Page 33: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

Question From where does the template class can derivedA Regular non-templated c++ classB Templated classC Both a and bD None of the above mentionedAnswer CMarks 2Unit IV

Id 133Question What is done by compiler for templatesA Type-safeB Code eliminationC PortabilityD All of the above mentionedAnswer AMarks 2Unit IV

Id 134Question Catch handler itself may detect and throw an exceptionA TrueB FalseCDAnswer AMarks 1Unit Iv

Id 135Question If the thrown exception will not be caught by any catch statement then it will be passed to

next outer try/catch sequence for processing.A FalseB TrueCDAnswer BMarks 1Unit IV

Id 136Question While specifying the exceptions, the type-list specifies the________ that may be thrown.A How many exceptionsB Type of exceptionC Both a and bD None of the above mentioned

Page 34: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

Answer BMarks 2Unit IV

Id 137Question When an exception is rethrown ,it will not be caught by the__________or other catch in

that group.A Same catchB Nested catchC Both a and bD None of the above mentionedAnswer AMarks 2Unit IV

Id 138Question Try block can throw any exceptionA TrueB FalseCDAnswer BMarks 1Unit IV

Id 139Question Pick up the correct statement from the following

• Multiple catch statement are there in c++.• We have generic catch statement to handle all type of exception• Try block is used to throw and exception

A i and iiiB iC iiD i and ii onlyAnswer DMarks 2Unit IV

Id 140Question When an exception is not caught A Program is go in wait conditionB Program is abortedC Program works fine wayD None of the above mentionedAnswer B

Page 35: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

Marks 1Unit IV

Id 141Question We can place two or more catch blocks together to catch and handle multiple types of

exceptions thrown by a try blocksA True B FalseCDAnswer AMarks 1Unit IV

Id 142Question It is also possible to make a catch statement to catch all types of exceptions using ellipses

as its argumentsA TrueB FalseCDAnswer AMarks 1Unit IV

Id 143Question We can restrict a function to throw only a set of specified exceptions by adding a throw

specification clause to the function definition.A True B FalseCDAnswer AMarks 1Unit IV

Id 144Question We may also use non-type parameters such basic or derived data types as arguments

templateA TrueB FalseCDAnswer AMarks 1Unit IV

Page 36: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

Id 145Question Pick up the correct statement from the following related with overloading of template

functions• Call an ordinary function that has an exact match• Call a template function that could be created with an exact macth• Try normal overloading resolution to ordinary functions and call the one

that matchesA 1 and 2 onlyB 2 and 3 onlyC All of the aboveD None of the above mentionedAnswer CMarks 2Unit IV

Id 146Question What will be output of the a following program

#include<iostream>using namespace std;template <class T>void display(T x){cout<<“Template display:”<<x<< “\n”;}void display(int x){cout<<“Explicit display:”<<x <<“\n”;}int main(){display(100);display(12.34);display(‘c’);}

A Template display:100Template display:12.34Template display: c

B Explicit display:100Template display:12.34Template display: c

C Explicit display:100Template display:12.34Explicit display: c

D Template display:100Template display:12.34

Page 37: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

Template display: cAnswer BMarks 2Unit IV

Id 147Question What will be output of program

#include <iostream>using namespace std;int main(){cout <<"Start\n";try {cout <<"Inside try block\n";throw 100;cout << "This will not execute";}catch (int i) {cout <<"Caught an exception -- value is: ";cout <<i <<"\n";}cout <<"End";return 0;}

A StartInside try blockCaught an exception -- value is: 100End

B StartEnd

C StartInside try blockEnd

D None of the above mentionedAnswer AMarks 2Unit IV

Id 148Question What will be output of following program

#include <iostream>using namespace std;void Xhandler(int test){try{if(test) throw test;

Page 38: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

else throw "Value is zero";}catch(int i) {cout << "Caught Exception #: " <<i <<'\n';}catch(const char *str) {cout <<"Caught a string: ";cout << str <<'\n';}}int main(){cout <<"Start\n";Xhandler(1);Xhandler(2);Xhandler(0);Xhandler(3);cout << "End";return 0;}

A StartCaught Exception #: 1Caught Exception #: 2Caught Exception #: 0Caught Exception #: 3End

B StartCaught Exception #: 1Caught Exception #: 2Caught a string: 0Caught Exception #: 3End

C StartCaught Exception #: 1Caught Exception #: 2Caught a string: Value is zeroCaught Exception #: 3End

D None of the mentionedAnswer CMarks 2Unit IV

Id 149Question What will be output of program

#include <iostream>

Page 39: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

using namespace std;void Xhandler(int test){try{if(test==0) throw test; // throw intif(test==1) throw 'a'; // throw charif(test==2) throw 123.23; // throw double}catch(int i) { // catch an int exceptioncout <<"Caught an integer\n";}catch(...) { // catch all other exceptionscout <<"Caught One!\n";}}int main(){cout <<"Start\n";Xhandler(0);Xhandler(1);Xhandler(2);cout <<"End";return 0;}

A StartCaught One!Caught One!Caught One!End

BC Start

Caught an integerCaught One!Caught One!End

D StartCaught One!Caught an integerCaught One!End

Answer CMarks 2Unit None of the above mentioned

Id 150Question What will be output of following program

Page 40: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

#include <iostream>using namespace std;template <class Type1, class Type2> class myclass{Type1 i;Type2 j;public:myclass(Type1 a, Type2 b) { i = a; j = b; }void show() { cout <<i << ' ' <<j <<'\n'; }};int main(){myclass<int, double>ob1(10, 0.23);myclass<char, char *>ob2('X', "Templates add power.");ob1.show(); // show int, doubleob2.show(); // show char, char *return 0;}

A 10 0.23X Templates add power.

B 0.23 10X Template add power

C 10 10X template add power

D Compilation errorAnswer AMarks 2Unit IV

Id 151Question We can combine operator overloading with a class A TrueB FalseCDAnswer AMarks 1Unit IV

Id 152Question If you overload a generic function, that overloaded function overrides (or "hides") the

generic function relative to that specific version.A TrueB FalseCD

Page 41: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

Answer AMarks 1Unit IV

Id 153Question What will be output of following programming

#include <iostream>using namespace std;template <class T>T GetMax (T a, T b) {T result;result = (a>b)? a : b;return (result);}int main () {int i=5, j=6, k;long l=10, m=5, n;k=GetMax<int>(i,j);n=GetMax<long>(l,m);cout <<k << endl;cout <<n <<endl;return 0;}

A 610

B 55

C 1010

D Compilation errorAnswer AMarks 2Unit IV

Id 154Question What will be output of following program

#include <iostream>using namespace std;template <class T>class mypair {T a, b;public:mypair (T first, T second){a=first; b=second;}T getmax ();};

Page 42: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

template <class T>T mypair<T>::getmax (){T retval;retval = a>b? a : b;return retval;}int main () {mypair <int>myobject (100, 75);cout << myobject.getmax();return 0;}

A 75B 100C 75

100D Compilation errorAnswer BMarks 2Unit IV

Id 155Question What will be output of following program

#include <iostream>#include <exception>using namespace std;class myexception: public exception{virtual const char* what() const throw(){return "My exception happened";}} myex;int main () {try{throw myex;}catch (exception&e){cout << e.what() <<endl;}return 0;}

A Exception happenedB My exception happened.

Page 43: kainjan1.files.wordpress.com  · Web view#include using namespace std;int main(){int x = -1;try {cout

C Run Time errorD Compilation errorAnswer BMarks 2Unit IV

Id 156Question Pick up the correct statement from following

1.Exception handling is not supported c++2.Template support generic programming in c++3.overloading of function template is possible in c++4.generic catch template can handle all types of exceptions

A 2 and 3 onlyB 3 and 4 onlyC 1, 2 and 3 onlyD 2, 3 and 4 onlyAnswer DMarks 2Unit IV


Recommended