Вы находитесь на странице: 1из 17

OBJECTIVE QUESTIONS IN C++ Sample -2

1 Which one is use for standard C++ comment. a. / b. /* */ c. // d. None 2 Constructor is called when a. a method is declared b. a class is declared c. a object is declared d. None 3 Function overloading in C++ is a. a group function with the same name b. all have the same number and type of arguments c. functions with same name and same number and type of arguments d. None 4 What is output of follwoing int main() { cout << "R4R" << endl; return 0; } a. Execution time error b. Syntax error c. R4R d. None 5 Strings are character arrays. The last index of it contains the null-terminated character a. \n b. \t c. \0 d. \1 6 C++ was invented by a. Donald Drum b. Ken Thompson c. Bjarne Stroustrup d. Dennis Ritchie

7. What the use of preprocessor directory(# include) a. Used for console output b. Used for console input c. Used for both console input and output d. none of the above

8. Destructor can contain a. Zero arguments b. One arguments c. Two arguments d. Four arguments 9. Opertor Overloading is like that a. giving new meaning to existing C++ operators b. making c++ operators works with objects c. both a and b d. none 10. Evaluate !(1 && !(0 || 1)). a. True b. False c. Unevaluatable d. none 11. The continue statement a. resumes the program if it is hanged b. resumes the program if break was applied c. skips the rest of the loop in current iteration d. all of above 12 . Identify the correct statement a. Programmer can use comments to include short explanations within the source code itself. b. All lines beginning with two slash signs are considered comments. c. Comments very important effect on the behaviour of the program d. both 13. a. b. c. d. Which of the following is false? Cout represents the standard output stream in c++. Cout is declared in the iostream standard file Cout is declared within the std namespace None of above

14. Which of the following can not be used as valid identifier? a. bitand b. bittand c. biand d. band 15. Which of the following is not a valid escape code? a. \t b. \v c. \f d. \w 16 .Which of the following statement is true? a. String Literals can extend to more than a single line of code by putting a backslash sign at the end of each unfinished line. b. You can also concatenate several string constants separating them by one or several blank spaces, tabulators, newline or any other valid blank character c. If we want the string literal to explicitly made of wide characters, we can precede the constant with the L prefix d. All of above 17. a. b. c. d. 18. a. b. c. d. In an assignment statement The lvalue must always be a variable The rvalue might be a constant, a variable, an expression or any combination of these The assignment always takes place from right to left and never the other way All of above Regarding #difine which of the following statement is false? It is not C++ statement but the directive for the preprocessor This does not require a semicolon at the end of line It is a C++ statement that declares a constant in C++ None of the above

19. Examine the following program and determine the output #include <iostream> using namespace std; int operate (int a, int b) { return (a * b); } float operate (float a, float b) { return (a/b); } int main() { int x=5, y=2; float n=5.0, m=2.0; cout << operate(x,y) <<"\t"; cout << operate (n,m);

return 0; } a. 10.0 b. 5.0 c. 10.0 d. 10

5.0 2.5 5 2.5

20. void main() { int a, *pa, &ra; pa = &a; ra = a; cout "a="a "*pa="*pa "ra"ra ; } a. Compiler Error b. Run time error c. Syntax error d. none of above 21. #include iostream.h class fig2d { int dim1; int dim2; public: fig2d() { dim1=5; dim2=6;} virtual void operator(ostream & rhs); }; void fig2d::operator(ostream &rhs) { rhs this->dim1" "this->dim2" "; } /*class fig3d : public fig2d { int dim3; public: fig3d() { dim3=7;} virtual void operator(ostream &rhs); }; void fig3d::operator(ostream &rhs) { fig2d::operator (rhs); rhsthis -> dim3; } */

void main() { fig2d obj1; // fig3d obj2; // } obj1 cout; obj2 cout;

a. 5 6 b. compilation error c. syntax error d. 6 8 22. class complex{ double re; double im; public: complex() : re(0),im(0) {} complex(double n) { re=n,im=n;}; complex(int m,int n) { re=m,im=n;} void print() { coutre; coutim;} }; void main(){ complex c3; double i=5; c3 = i; c3.print(); } a. 5,5 b. 6,6 c. Run time error d. compilation error 23. We declare a function with ______ if it does not have any return type a. long b. double c. void d. int

24. Which one is one of the OODBMS available. a. GEMSTONE/OPAL of Gemstone systems. b. ONTOS of Ontos. c. Objectivity of Objectivity inc. d. all of these

25. Which of these is/are some object-oriented methodologies. a. Object Oriented Development (OOD) (Booch 1991,1994). b. Object Oriented Analysis and Design (OOA/D) (Coad and Yourdon 1991). c. Object Modelling Techniques (OMT) (Rumbaugh 1991). d. All of these 26 . Which one is not pure object oriented languages. a. Smalltalk, b. Cobol c. Eiffel, d. Java 27. Name the operators that cannot be overloaded. a. * b. :: c. ?: d. all of these 28. When does the memory leak occur? a. A memory leak occurs when a program loses the ability to free a block of dynamically allocated memory. b. A memory leak occurs when program data overflows. c. Memory leak never occurs. d. Memory leak occur when pointer points to invalid entry. 29. What is slicing? a. Slicing is a procedure that is used to destruct a subclass under given condition. b. Slicing means that the data added by a subclass are discarded when an object of the subclass is passed or returned by value or from a function expecting a base class object. c. Slicing means truncating the subclass when condition is satisfy. d. none of these 30. Which statement is correct about smart pointer? a. A smart pointer is an object that acts, looks and feels like a normal pointer but offers more functionality. b. In C++, smart pointers are implemented as template classes that encapsulate a pointer and override standard pointer operators. c. They are guaranteed to be initialized as either null pointers or pointers to a heap object. Indirection through a null pointer is checked. No delete is ever necessary. d. all of above 31. Which statement is correct about reflexive association? a. The 'is-a' is called a reflexive association because the reflexive association permits classes to bear the is-a association not only with their super-classes but also with themselves. b. It differs from a 'specializes-from' as 'specializes-from' is usually used to describe the association between a super-class and a sub-class. c. Both a and b.

d. None of these. 32 .What is cloning? a. setting itself to be a copy of another object b. returning a copy of itself. c. none of these d. both 33. What do u meant by "SBI" of an object? a. SBI stands for State, Behavior and Identity. b. SBI stands for State Bank of India c. SBI stands for State, Behaviour and inheritance. d. none of above. 34. What do you meant by active and passive objects? a. Active object are dynamic. Passive are static. b. Active objects are one which instigate an interaction which owns a thread and they are responsible for handling control to other objects. Passive objects are one, which passively waits for the message to be processed. It waits for another object that requires its services. c. Active object can be referred as client. Passive objects can be referred as server. d. both b and c. 35. Differentiate persistent & non-persistent objects? a.Persistent refers to an object's ability to transcend time or space. A non-persistent object is said to be transient or ephemeral. b. A persistent object stores/saves its state in a permanent storage system with out losing the information represented by the object. default objects are considered as non-persistent. c. Both and b. d. none of these. 36. What are models and meta models? a. Model: It is a complete description of something (i.e. system). Meta model: It describes the model elements, syntax and semantics of the notation that allows their manipulation. b. Meta Model: It is a complete description of something (i.e. system). Model: It describes the model elements, syntax and semantics of the notation that allows their manipulation. c. both are correct. d. none of these. 37 . What is the difference between a template class and class template? a. Both are same. b. Template class: A generic definition or a parameterized class not instantiated until the client provides the needed information. Class template: It specifies how individual classes can be constructed much like the way a class specifies how individual objects can be constructed. c. Template class: It's jargon for plain templates.

Class template: It's jargon for plain classes. d. Both b and c. 38. a. b. c. d. 39. a. b. c. d. Which of the following is not a valid relational operator? == => >= >= The result of a Relational operation is always either True or False is less than or is more than is equal or less or more All of these

40. In case of arguments passed by values when calling a function such as z=addidion(x,y), a. Any modifications to the variables x & y from inside the function will not have any effect outside the function. b. The variables x and y will be updated when any modification is done in the function c. The variables x and y are passed to the function addition d. None of above are valid. 41. When following piece of code is executed, what happens? b = 3; a = b++; a. a contains 3 and b contains 4 b. a contains 4 and b contains 4 c. a contains 4 and b contains 3 d. a contains 3 and b contains 3 42. a. b. c. d. Which of the following identifiers is invalid? papername writername typename printname

43 .Regarding #difine which of the following statement is false? a. It is not C++ statement but the directive for the preprocessor b. This does not require a semicolon at the end of line c. It is a C++ statement that declares a constant in C++ d. None of the above 44 Inline functions involves some additional overhead in running time. a. yes b. no c. Cannt say

45 A function that calls itself for its processing is known as a. Inline Function b. Recursive function c. Overloaded Function d. Nested Function 46. Find the output of the following program class Sample { public: int *ptr; Sample(int i) { ptr = new int(i); } ~Sample() { delete ptr; } void PrintVal() { cout << "The value is " << *ptr; } }; void SomeFunc(Sample x) { cout << "Say i am in someFunc " << endl; } int main()

{ Sample s1= 10; SomeFunc(s1); s1.PrintVal(); } a. Compilation error b. Say i am in someFunc Null pointer assignment(Run-time error) c. Run-time error
d. None of the above

47. Which of the statement are correct about modifier? a. A modifier, also called a modifying function is a member function that changes the value of at least one data member. b. An operation that modifies the state of an object. c. Modifiers are also known as 'mutators'. d. All of these. Ans d 48. Which is the parameter that is added to every non-static member function when it is called: a. new b. this c. void d. none of the above

49. Which of the statement are correct about an accessor? a. An accessor is a class operation that does not modify the state of an object. b.The accessor functions need to be declared as const operations. c. both a and b d. Accessor is used to access private method variables. Ans c 50. . Find the output of the following program:

class base { public: int bval; base(){ bval=0;} }; class deri:public base { public: int dval; deri(){ dval=1;} }; void SomeFunc(base *arr,int size) { for(int i=0; i cout<bval; cout< } int main() { base BaseArr[5]; SomeFunc(BaseArr,5); deri DeriArr[5]; SomeFunc(DeriArr,5); } a. 00000 01010 b. 01010 00000 a. 01010 10101 b. None of the above 51. Which of the following cant be declared static a. class b. functions c. member variables d. none of the above 52. Find the output of the following program class base { public:

void baseFun(){ cout<<"from base"< }; class deri:public base { public: void baseFun(){ cout<< "from derived"< }; void SomeFunc(base *baseObj) { baseObj->baseFun(); } int main() { base baseObject; SomeFunc(&baseObject); deri deriObject; SomeFunc(&deriObject); } a. from base from derived b. from derived from base c. from base from base d. from derived from derived 53. Choose the best answer. A function that does the same operation on different data types is top be implemented using a. macros b. overloading c. function templates d. default arguments 54. . Find the output of the following program const int size = 5; void print(int *ptr) { cout< } void print(int ptr[size]) { cout<

} void main() { int a[size] = {1,2,3,4,5}; int *b = new int(size); print(a); print(b); } a. run time error b. compilation error c. segmentation fault d. none of the above 55. which of the following decides if a function that is declared inline is indeed going to be treated inline in executable code a. compiler b. linker c. loader d. preprocessor 56. Find the output of the following program class some{ public: ~some() { cout<<"some's destructor"< } }; void main() { some s; s.~some(); } a. some's destructor b. compilation error c. some's destructor some's destructor d. run time error 57. Forgetting to include a file that is necessary will result in a. warning message

b. compilation error c. link time error d. run time error 58 . Find the output of the following program class opOverload{ public: bool operator==(opOverload temp); }; bool opOverload::operator==(opOverload temp){ if(*this == temp ){ cout<<"The both are same objects\n"; return true; } else{ cout<<"The both are different\n"; return false; } } void main(){ opOverload a1, a2; a1= =a2; } a. b. c. d. The both are different The both are same objects Compilation error Run time error

59. The fields in a structure of a c program are by default a. protected b. private c. public. d. none of the above. 60. 53. Find the output of the following program class complex{ double re; double im; public: complex() : re(1),im(0.5) {} bool operator==(complex &rhs);

operator int(){} }; bool complex::operator == (complex &rhs){ if((this->re == rhs.re) && (this->im == rhs.im)) return true; else return false; } int main(){ complex c1; cout<< c1; } a. True b. Garbage value c. False d. None of the above 61. reference is not same as pointer because a. a reference can never be null b. a reference once established cant be exchanged c. reference doesnt need an explicit dereferencing mechanism d. all of the above 62. Find the output of the following program class base { public: virtual void baseFun(){ cout<<"from base"< }; class deri:public base { public: void baseFun(){ cout<< "from derived"< }; void SomeFunc(base *baseObj) { baseObj->baseFun(); } int main() { base baseObject; SomeFunc(&baseObject);

deri deriObject; SomeFunc(&deriObject); } a. from base from derived b. from derived from base c. from base from base d. from derived from derived 63. which of the following parameter passing is supported by C++ , but not by c? a. Pass by value b. Pass by reference c. Pass by value-result d. all of the above. 64. C++ encourages structuring a software as a collection of components that are a. highly cohesive and loosely coupled b. not highly cohesive but loosely coupled c. highly cohesive and tightly coupled d. not highly cohesive but tightly coupled 65. overloading is otherwise called as a. virtual polymorphism b. transient polymorphism c. pseudo polymorphism d. ad-hoc polymorphism 66. Choose the correct answer. a. in a struct, the access control is public by default b. in a struct, the access control is private by default c. in a class, the access control is public by default. d. none of the above 67. for a method to be interface between the outside world and a class, it has to be declared a. private b. protected c. public d. external 68. A class having no name

a. cant have a constructor b. cant have a destructor c. cant be passed as an argument d. all of the above 69. The keyword asm is used to: a. specify a class declaration b. specify a constant definition c. allow information to be passed to the assembler directly d. store the class for objects declared outside the local block

70. An object of the stack class can hold data that: a. is an object of a class derived from object b. is an object of a container class c. is an object of a non container class d. all of the above.

ANSWERS
1. C 11. c 21. a 31. c 41. a 51. a 61. d 2. C 12. b 22. a 32. b 42. c 52. c 62. a 3. A 13. d 23. c 33. a 43. c 53. c 63. c 4. c 14. a 24. d 34. d 44. a 54. b 64. a 5. c 15. d 25. d 35. c 45. b 55. a 65. d 6. c 16. d 26. b 36. a 46. b 56. c 66. a 7. c 17. d 27. d 37. d 47. d 57. c 67. c 8. a 18. c 28. a 38. b 48. b 58. d 68. d 9. c 19. d 29. b 39. a 49. c 59. c 69. c 10. a 20. a 30. d 40. a 50. a 60. b 70. d

Вам также может понравиться