You are on page 1of 13

C++ Questions & Answers JECRC UNIVERSITY JAIPUR

SET-3 and SET-4
1. If the class name is X, what is the type of its “this” pointer (in a nonstatic, non-const member
function)?
a. const X* const
b. X* const
c. X*
d. X&

2. Which classes allow primitive types to be accessed as objects?
a. Storage
b. Virtual
c. Friend
d. Wrapper

3. When is std::bad_alloc exception thrown?
a. When new operator cannot allocate memory
b. When alloc function fails
c. When type requested for new operation is considered bad, thisexception is thrown
d. When delete operator cannot delete teh allocated (corrupted) object

4. Which one of the following is not a fundamental data type in C++
a. float
b. string
c. int
d. wchar_t

5. Which of the following is a valid destructor of the class name "Country"
a. int ~Country()
b. Country()
c. int ~Country(Country obj)
d. ~Country()

6. Which of the following correctly describes C++ language?
a. Statically typed language
b. Dynamically typed language
c. Both Statically and dynamically typed language
d. Type-less language

7. Which of the following keyword supports dynamic method resolution?
a. abstract
b. Virtual
c. Dynamic
d. Typeid

8. Which of the following is the most preferred way of throwing and handling exceptions?
a. Throw by value and catch by reference.
b. Throw by reference and catch by reference.
c. Throw by value and catch by value
d. Throw the pointer value and provide catch for teh pointer type.

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)

What's wrong? for (int k = 2. std::vector b. Function definitions d. std::set 16. Type definitions (typedefs) b. A continue statement causes execution to skip to a. They form an integral part of the code d. the test condition is always false d. Template definitions 15. the commas should be semicolons 14. Which of the STL containers store the elements contiguously (in adjecent memory locations)? a. std::bad_creat b. the conditional operator is only used with apstrings 13. Standard Template Library Question Prepared By : Shekhar (IT Dept . std::map d. statement b. the statement following the continue statement d. They have to end with a semi colon 10. std::bad_cast d. the test condition is always true 11. What does STL stand for? a. the while loop is an exit-condition loop c. std::bad_typeid 17. std::bad_alloc c.C++ Questions & Answers JECRC UNIVERSITY JAIPUR 9. the next iteration of the loop 12.JECRC University Jaipur) . a. What's wrong? while( (i < 10) && (i > 24)) a. the first semicolon should be a colon c. there should be a semicolon at the end of the statement d. std::list c. k <=12. the variable must always be the letter i when using a for loop c. (b = 6). the question mark should be an equal sign b. They begin with a hash symbol b. there are too many variables in the statement d. Class definitions c. the return 0. Which of the following is not a standard exception built in C++. Which of the following is not recommended in a header file? a. Which of the following is not true about preprocessor directives a. the increment should always be ++k b. They are processed by a preprocessor c. a. What's wrong? (x = 4 && y = 5) ? (a = 5) . k++) a. the first statement after the loop c. the logical operator && cannot be used in a test condition b. Simple Template Library b.

Each pass through a loop is called a/an a. const members can be invoked only on const objects and not on nonconst objects c. c. Which of the following relationship is known as inheritancerelationship? a. pass through 21. Auxiliary storage management c. If class A is friend of class B and if class B is friend of class C. Which one of the following is not a valid reserved keyword in C++ a. ‘has-a’ relationship b. Private 20. enumeration b. Public c. Class C is friend of class A b. Single Type-based Library 18. Class A and Class C do not have any friend relationship d. Redefining a function in a friend class is called function overloading while Redefining a function in a derived class is called as overridden fucnion. Overloading is a dynamic or run-time binding and Overriding is static or compile-time binding b. const members can be invoked on both const as well as nonconst objects b. Overloading is a static or compile-time binding and Overriding is dynamic or run-time binding d. culmination d. Redefining a function in a friend class is called function overriding while Redefining a function in a derived class is called a overloaded fucntion. Files which are stored on a direct access storage medium d. Free integrity mechanism Question Prepared By : Shekhar (IT Dept . None of the above 25. association relationship d. A file in which recoreds are arranged in a way they are inserted in a file b. iteration c. none of the 23. Implicit d. ‘is-a’ relationship c.JECRC University Jaipur) . which of the following is true? a.C++ Questions & Answers JECRC UNIVERSITY JAIPUR c. A direct access file is: a. What is the difference between overloaded functions and overridden functions? a. Which of the following is true about const member functions? a. Class A is friend of class C c. nonconst members can be invoked on const objects as well as nonconst objects d. Explicit b. None of the above 24. A file in which records are arranged in a particular order c. Static Type Library d. Access method b. none of the above 22. 19. Which of the following is not a component of file system a.

Locates information about data in small files that are maintained apart from actual data record b. Data processing language d. It is setting the compiler option conditionally c. An inverted file a. None of above 34. None of the above 31. General purpose language c. A file which stores opposite records c. It is compiling a program based on a condition d. ‘Prime area’ in context of file system is defined as a. Originally ‘C’ was developed as: a. ptr++ b. It is the main area of a web page d.C++ Questions & Answers JECRC UNIVERSITY JAIPUR d. None of the above 30. Time taken by appropriate sector to come under read/write d. Both a & b d. *ptr c. None of the above 28. Which of the following is not a file operation: Question Prepared By : Shekhar (IT Dept .JECRC University Jaipur) . In mulit-list organization a. None of the above 27. None of the above 26. ++*ptr d. Simultaneous read operations can be overlapped b. The conditional compilation a. Which of the following is/are advantages of cellular partitioned structure: a. time taken to retrieve a dta b. A file which stores information about records of a system d. None of above 33. Records are loaded in ordered sequence defined by collating sequence by content of the key c. none of above 32. None of the above 29. It is taken care of by the compiler b. It is memory area created by operating system b. Records that have equivalent value for a given secondary index item are linked together to form a list. Records are directly accessed by record key field d. System programming language b. *ptr++ is equivalenet to: a. Seek time is a. b. It is an area into which data records are written c. Time taken by read/write head mechanism to position itself over appropriate cylinder c. Search time is reduced c.

Exception Handling b. while c. namespaces provide facilities for organizing the names in a program to avoid name clashes 42. Appending d. None of above 37. 41. Which looping process checks the test condition at the end of the loop? a.JECRC University Jaipur) . How many copies of a class static member are shared between objects of the class? a. Namespaces refer to packing structure of classes in a program. Needs to be assigned 40. Key sequenced structure. Namespaces refer to the memory space allocated for names used in a program b.C++ Questions & Answers JECRC UNIVERSITY JAIPUR a. The default access level assigned to members of a class is ___________ a. Private b. Reflection c. Namespaces refer to space between the names in a program c. Entry sequence structure. exit sequenced structure d. Namespaces refer to space between the names in a program d. Which of the following correctly describes the meaning of‘namespace’ feature in C++? a. The two types of file structure existing in VSAM file are a. Which of the following correctly describes the meaning of ‘namespace’ feature in C++? a. None of above 35. Operator Overloading Question Prepared By : Shekhar (IT Dept . A copy is created only when at least one object is created from that class c. Time taken by appropriate sector to come under read/write head d. Time taken to transfer a dta from memory c. Repositioning b. Namespaces refer to the memory space allocated for names used in a program b. Truncating c. None of above 36. no looping process checks the test condition at the end 39. No memory is allocated for static members of a class 38. exit sequenced structure c. d. Namespaces provide facilities for organizing the names in aprogram to avoid name clashes. Which of the following language is not supported by C++? a. Namespaces refer to space between teh names in a program c. for b. A copy of the static member is shared by all objects of a class b. entry sequenced structure b. Protected d. Time taken by read/write head mechanism to position itself over appropriate cylinder b. Key sequence structure. A copy of the static member is created for each instntiation of the class d. Public c. Latency time is: a. do-while d.

It has large storage capacity c. By declaring the class abstract with the keyword ‘abstract’ d. Expression C=i++ causes a. It is easily portable 48. Which of the following languages is a subset of C++ language? a. It can cause a failure c. Question Prepared By : Shekhar (IT Dept . Which of the following language feature is not an access specifier in C++? a. How do we declare an ‘interface’ class? a. It is cost-effective b. i to be incremented by 1 and then value of i assigned to C c. i = i + i.) in a class b. language 45.JECRC University Jaipur) . i to be incremented by 1 51. It is not possible to create interface class in C++ 46. Java Language c. What happens when a pointer is deleted twice? a. It can abort the program b.C++ Questions & Answers JECRC UNIVERSITY JAIPUR d. internal 50. By declaring the class as interface with the keyword ‘interface’ d. C# language d. By providing at least one pure virtual method (function signature followed by ==0. Multiple inheritance 44. How do we declare an abstract class? a. It has highest speed d. Multilevel inheritance c. Which of the following is not an advantage of secondary memory a. public base2 { } is an example of a. By making all the methods pure virtual in a class b. By declaring at least one method abstract using the keyword ‘abstract’ in a class c. It can cause a trap 49. C language b. Hierarchical inheritance d. By making all the methods abstract using the keyword ‘abstract’ in a class c. It can cause an error d. Polymorphic inheritance b. Namespaces 43. private c. It is not possible to create abstract classes in C++ 47. public b. is equivalent to a. Value of i assigned to C and then i incremented by 1 b. Value of i assigned to C d. class derived: public base1. The statement i++. C protected d.

declare the member as a. 52. Vtables a. Terminate() b.j are integer type and ix long type would be a. what is the order in which the constructers of those classes are called a. ~X() {} 58. creates a static table per object c. Static variable inside class d. Abort() d. if i. D. Value of ix+j. creates a static table per class b. B. C. Class B first Class A next Question Prepared By : Shekhar (IT Dept . h 53. Local variable inside constructor c. c. i --. exit() 54. In C language. D. i = i . i = i + 1. d.1. cast_dynamic 57. How do we define a constructor? a. A. x b. a hexadecimal number is represented by writing a. c. ox d. end() c. Which of the following library function below by default aborts the program? a. Global variable outside class b. float c. Which of the following below can perform conversions between pointers to related classes? a. integer b. X() {}~ c. Class A first Class B next b. creates a dynamic table per class d. B. double percision 56. When class B is inherited from class A.JECRC University Jaipur) .C++ Questions & Answers JECRC UNIVERSITY JAIPUR b. X() ~{} d. creates a dynamic table per object 59. If a member needs to have unique value for all the objects of that same class. dynamic_cast c. a. static_cast d. Dynamic variable inside class 55. x~() {} b. long integer d. cast_static b. xo c.

catch(std::exception) b.JECRC University Jaipur) . Class B's only as it is the child class d. Depends on how it is invoked d. What is shallow copy? a. Both b and c above 66. Forward Iterator d. the innermost loop c. catch(std::exception) b. What is deep copy? a. Compile time c. By default all the struct members are public while by default class members are protected. Which of the following is the most general exception handler that catches exception of any type? a.C++ Questions & Answers JECRC UNIVERSITY JAIPUR c. A deep copy creates a copy of the statically allocated objects too d. b. catch(std::any_exception) c. By default all the struct members are protected while by default class members are private. cannot be determined without knowing the size of the loops 63. c. Which of the following below is /are a valid iterator type? a. In a group of nested loops. catch(std::any_exception) c. A shallow copy creates a copy of the dynamically allocated objects too. Input Iterator b. Inline functions are invoked at the time of a. Which of the following is the most general exception handler that catches exception of ‘any type’? a. A shallow copy creates a copy of the statically allocated objects too d. catch(…) d. d. b. A deep copy just copies the values of the data as they are. the outermost loop b. Both b and c above 65. catch() 62. Both a and c above Question Prepared By : Shekhar (IT Dept . Both b and c above 67. all loops are executed the same number of times d. c. Backward Iterator c. By default all the struct members are public while by default class members are private. Run time b. catch(…) d. c. b. A shallow copy just copies the values of the data as they are. What is the Difference between struct and class in terms of Access Modifier? a. catch() 61. A deep copy creates a copy of the dynamically allocated objects too. which loop is executed the most number of times? a. 64. By default all the struct members are private while by default class members are public. Class A's only as it is the parent class 60.

a. Which looping process is best used when the number of iterations is known? Question Prepared By : Shekhar (IT Dept . Structured Programming b. Print the value of i d. Functional Programming d. Aspect Oriented Programming (AOP) 73. Explicitly. Class template d.JECRC University Jaipur) . synchronization takes place? a. Assign an float to variable i 72. When the buffer is empty c. Functional Programming d. malloc() c. parentheses ( ) b. which of the following must be placed at the beginning and the ending of the loop block? a. Statement scanf(“%d”. Protected d. What defines a general set of operations that will be applied to various types of data? a. Object Oriented Programming (OOP) c. braces { } c. d. Public b. If there is more than one statement in the block of a for loop. Structured Programming b. Which of the following functions below can be used Allocate space for array in memory? a. Assign an integer to variable i b. both a and c 70. arrows < > 75. All the above 76. Aspect Oriented Programming (AOP) 74. Realloc() d.80). calloc() b. Function template c. Private c. Which of the following members do get inherited but become private members in child class a. STL is based on which of the following programmingparadigms? a. with manipulators d. STL is based on which of the following programming paradigms? a. Object Oriented Programming (OOP) c. both a and b 71. When the file is closed b. Give an error message c. brackets [ ]. Both a and c above 69. Template class b. Under which of the following circumstances.C++ Questions & Answers JECRC UNIVERSITY JAIPUR 68.

Which of the following is the most common way of implementing C++? a. sizeof operator d. while c. <autoptr> d. A digit b.C++ Questions & Answers JECRC UNIVERSITY JAIPUR a. do-while d. [. (array access operator) d. () (function call operator) c.JECRC University Jaipur) . + (addition operator) 81. –> (row operator) d. == (equality operator) c. Which of the following operators below allow to define the member functions of a class outside the class? a. <alloc> c. In a C language ‘3’ represents a. Which header file should we include for using std::auto_ptr? a. & (address-of operator) c. Which of the following operators can be implemented as a nonmember operator? #NAME? b. . std::auto_ptr pointer c. all looping processes require that the iterations be known 77. :: (cope resolution operator) 84. <memory> b. A word 78. :: Question Prepared By : Shekhar (IT Dept . (dot or member access operator) b. C++ programs are directly compiled into native code by a compiler b. ‘this’ pointer 82. for b. A character d. ‘self’ pointer b. An integer c. ‘Myself’ pointer d. What is the implicit pointer that is passed as the first argument for nonstatic member functions? a. C++ programs are first compiled to intermediate code by a compiler and then executed by a virtual machine c. C++ programs are interpreted by an interpreter d. Which of the following operator cannot be overloaded? #NAME? b. <smartptr> 80. Which of the following operators can be overloaded? a. A C++ editor directly compiles and executes the program 79. ?: (conditional operator) 83.

Which of the following is not a standard exception built in C++. std::bad_alloc c. Minimum number of temporary variable needed to swap the contents of 2 variables is: a. Static variable inside class d. #endif d. malloc() c. If a member needs to have unique value for all the objects of that same class. 1 b. synchronization takes place? a. When the buffer is empty c.JECRC University Jaipur) . a. 2 c. std::bad_typeid 87. Global variable outside class b. calloc() b. Which of the following is not a valid conditional inclusions in preprocessor directives a. Syntax error c. b + 5). When the file is closed b. Value of a in a = (b = 5. is a. Under which of the following circumstances. #elif 91. #ifdef b. % 85. std::bad_creat b. Local variable inside constructor c. Junk value b. Dynamic variable inside class 88. Which of the following is not a valid conditional inclusions in preprocessor directives a. #elif 86. Realloc() d. #endif d. 5 d. Which of the following functions below can be used Allocate space for array in memory? a. 10 92.C++ Questions & Answers JECRC UNIVERSITY JAIPUR b. both a and b 90. both a and c 89. #ifundef c. #ifdef b. declare the member as a. Explicitly. with manipulators d. 3 Question Prepared By : Shekhar (IT Dept . std::bad_cast d. ? c. :? d. #ifundef c.

Syntax error d. The return value of the following code is Class1& test(Class1 obj) { Class1 *ptr = new Class1(). Syntax error c. } a. object of Class1 b. Hello World b. 20 10 Question Prepared By : Shekhar (IT Dept .. 5 b.. } a. This process is called as a. a.. There is nothing like a virtual constructor of a class. 0 d. Syntax error b. 10 20 c. reference to ptr c. Dynamic Binding 96. void main() { int a = 20... int b = 10. 10 c.. False b.JECRC University Jaipur) . . The output of this program is int a = 10. return ptr. 0 94. The output of this program is int main () { cout << "Hello World!" return 0.C++ Questions & Answers JECRC UNIVERSITY JAIPUR d. C++ provides facility to specify that the compiler should match function calls with the correct definition at the run time. Hello World! 97. cout << a << ::a. None of above 99.. reference of Class1 d. Static binding b.. object pointed by ptr 98. cout << (a>b?a:b). } a. The output of { int a = 5. } a. True 95.

C 58 .c 57 .c 74 .d 32 .c 12 .a 95 .c 20 .a 88 . Constructor 2 b.b 34 . 20 20 100.b 29 .d 93 .c 75 .c 62 .a 60 .c 81 .d 13 .a 47 . Constrcutor 1 d.a 48 . b = c = 1.b 22 .b 96 .a 41 .D 59 .b 97 .} //Constructor 4 } In the above example of constructor overloading.a 55 .c 33 .d 82 .d 45 .b Question Prepared By : Shekhar (IT Dept .a 72 .c 21 .c 16 .c 65 .} //Constructor 2 Example(int a.d 50 .c 26 .int c){ a = a. c = c.b 19 .d 94 .d 71 .} //Constructor 3 Example(int a.JECRC University Jaipur) .d 42 .b 56 .b 99 .a 78 .d 43 .c 77 .d 15 .3).a 52 .b 64 . Constructor 4 c.b 92 .a 30 .b 98 . b = b.d 85 .c.d 11 .int b.C++ Questions & Answers JECRC UNIVERSITY JAIPUR d.} //Constructor 1 Example(int a){a = a. Type mismatch error 1-d 2-b 3-d 4-a 5-b 6-d 7-a 8-b 9-a 10 .a 68 .a 17 .d 36 .int b){a = a. b = b.d 51 . the following statement will call which constructor Example obj = new Example (1.b 44 .d 27 .c 25 .d 90 . Example(){a=b=c=1.b 67 .b 14 .b 76 .b 89 .c 37 .a 91 .a 80 .b 28 .a 61 .d 69 .d 83 . Observe following program and answer class Example{ public: int a.b 70 .a 35 .b 84 .b 53 .2.c 40 .a 23 .c 79 .c 100 .b 87 .a 18 .c 63 .b.a 39 .c 31 .a 86 .a 46 .c 49 .c 38 .b 24 .b 66 .d 54 . a. c = 1.a 73 .