You are on page 1of 14

Q 1. How many values can be returned by a C++ function? 1 Infinity 0 None of the Above Q 2.

Virtual functions are defined in Derived class Base class Both A and B None of the Above Q 3. cin in C++ program uses the operator >> < << > Q 4. Which of the following denotes advantages of operator overloading? Operator not limited to operate only with primitive Data Type Extensibility Both A and B None of the Above Q 5. The friend function of a class in C++ can access Private members of the class protected members of the class Both A and B None of the Above Q 6. When dynamically allocated memory is lost to the C++ program then warning occurs memory leak occurs The program does not executes successfully None of the above

Page 1

Q 7.The operator that denotes address of a variable in C++ program is * % $ & Q 8.The overriding method must have the which of the following same as that of the method in the super class definition same identifier same signature Both A and B None of the Above Q 9.Which of the following is used in C++ to create a copy of an object? Assignment operator Copy constructor Both A) and B) None of the Above Q 10. Which of the following is used to group a set of global classes, objects and functions under a name? Area named Namearea Namespaces None of the above Q 11. Private Public Protected None of the Above Q 12. Private Public Protected None of the Above Q 13. The members of a class are by default Inheritance in C++ have default access specifier as

Page 2

// All the necessary libraries have been included // Consider the following code: void swap(int& a, int b) { long temp; temp=a; a=b; b=temp; } // If we have int x = 5 and y = 3, // what are values of x and y after swap(x,y) being called? x=3, y=3 x=5, y=3 x=3, y=5 x=5, y=5 Q 14. // All the necessary libraries have been included // Consider the following code: void g(int& a) { a = 13 ; } int f() { int a = 42 ; g( a ) ; return a ; } // What value is returned if f() is called? 13 42 0 There is a compile error in the code Q 15. void f() {

Page 3

int *p = new(nothrow) int ; if( p!=0 ) { *p = 99 ; delete p ; cout << *p << endl ; } } // What value is printed if f() is called? Unknown value 99 0 The code has a compile error Q 16. // All the necessary libraries have been included // Consider the following code: void f() { int *p = new(nothrow) int ; if( p!=0 ) { *p = 99 ; delete p ; p = NULL; cout << *p << endl ; } } // What value is printed if f() is called? The program will crash 99 0 NULL Q 17. // All the necessary libraries have been included // Consider the following code: void f() {

Page 4

int x = 10; int* const p = &x; *p = 5; cout << *p << endl; } // What value is printed if f() is called? 5 10 0 The code has a compile error. Q 18. // All the necessary libraries have been included // Consider the following code: void f() { int x = 10; int y = 20; int* const p = &x; *p = 5; p = &y; cout << *p << endl; } // What value is printed if f() is called? The code has a compile error. 5 20 0 Q 19. // All the necessary libraries have been included // Consider the following code: void f() { const int x = 10; const int* p = &x; ko thay doi bien *p = 5;

Page 5

cout << *p << endl; } // What value is printed if f() is called? The code has a compile error. 5 10 0 Q 20. // All the necessary libraries have been included // Consider the following code: class A { int x, y; public: void fa(int a) { cout << a + x + y; } }; class B : public A { public: void fb() { A a; a.x = 3; a.y = 5; a.fa(10); } }; // What value is printed if fb() method of class B is called? The code has a compile error 18 10 0 Q 21.
private

Page 6

// All the necessary libraries have been included // Consider the following code: class A { int x, y; public: void fa(int a) { cout << a + x + y; } friend class B; }; class B : A { public: void fb() { A a; a.x = 3; a.y = 5; a.fa(10); } }; // What value is printed if fb() method of class B is called? 18 10 0 The code has a compile error. Q 22. // All the necessary libraries have been included // Consider the following code: class A { protected: int x, y; public: void fa(int a) { cout << a + x + y;

Page 7

} }; class B : public A { public: void fb() { A a; a.x = 3; a.y = 5; a.fa(10); } }; // What value is printed if fb() method of class B is called? The code has a compile error. 10 0 18 Q 23. // All the necessary libraries have been included // Consider the following code: class A { int x, y; public: void fa(int a, int b) { cout << a + b; } void fa(double a, double b) { cout << a + b; } void fa(int a, double b) { cout << a + b; } }; // What value is printed if the following code is executed?

Page 8

// A a; a.fa(2, 3.2); 5.2 5 0.2 The code has a compile error. Q 24. // All the necessary libraries have been included // Consider the following code: class A { int x, y; public: void f() { cout << "father"; } }; class B : public A { public: void f() { cout << "son"; } }; // What value is printed if the following code is executed? // A* a = new B; a->f(); Father Son Fatherson The code has a compile error Q 25. // All the necessary libraries have been included // Consider the following code: class A { int x, y; public:

Page 9

void virtual f() { cout << "father"; } }; class B : public A { public: void virtual f() { cout << "son"; } }; // What value is printed if the following code is executed? // A* a = new B; a->f(); Son Father Sonfather The code has a compile error. Q 26. // All the necessary libraries have been included // Consider the following code: class A { public: int age; char* name; void print() const { ++age; cout << age << ", " << name << endl; } }; // What value is printed if the following code is executed? // A a1; // a1.age = 20; a1.name = "peter"; // a1.print(); The code has a compile error.

Page 10

21, peter 20, peter 22, peter Q 27. // All the necessary libraries have been included // Consider the following code: #define SIZE 5 class A { public: void increase(const int* grade) const { for (int i = 0; i < SIZE; i++) { grade[i] +=1; } } void sum() { int sum = 0; int grade[] = {1,2,3,4,5}; increase(grade); for (int i = 0; i < SIZE; i++) { sum += grade[i]; } cout << sum/SIZE << endl; } }; // What value is printed if the following code is executed? // A a1; a1.sum(); There is a compile error in the code. 4 3 5

Page 11

Q 28 class Person { public: Person(int p1) { cout << this->p1; } }; class Student : public Person { public: Student(int i) { cout << this->i; } }; int _tmain(int argc, _TCHAR* argv[]) { Person(123); Student(111); getch(); return 0; } //What is the output?? 123, 111 111, 123 The program has compiling errors. The program will crash when executing Q 29: What are the roles of constructor?

Q 30: If class A inherits from class B, which inherits from class C, what is the order of calling constructors and destructors?

Q 31: class Student has 2 private members: int age, string address. The Student class has a constructor that takes age and address as arguments. Implement an overloaded assignment operator that allows comparing two objects of the Student class. The two students objects are equal if both their age and address are equal.

Page 12

Q 32 Find errors if any

Q 33 Find errors if any

Q 34 Find errors if any

Page 13

Q 35 Find errors if any

Q 36 Improve the following code

Page 14

You might also like