Question: C++ MCQ : Q01. The address of a variable temp of type int is (A) *temp (B) &temp (C) int& temp (D) int temp& Q02.
C++ MCQ :
Q01. The address of a variable temp of type int is (A) *temp (B) &temp (C) int& temp (D) int temp&
Q02. If a class C is derived from class B, which is derived from class A, all through public inheritance, then a class C member function can access (A) protected and public data only in C and B. (B) protected and public data only in C. (C) private data in A and B. (D) protected data in A and B.
Q03. Usually a pure virtual function (A) has a complete function body. (B) will never be called. (C) will be called only to delete an object. (D) is defined only in derived class.
Q04. Run-Time Polymorphism is achieved by ______ (A) friend function (B) virtual function (C) operator overloading (D) function overloading
Q05. The keyword friend does not appear in (A) the class allowing access to another class. (B) the class desiring access to another class. (C) the private section of a class. (D) the public section of a class.
Q06. Use of virtual functions implies (A) overloading. (B) overriding. (C) static binding. (D) dynamic binding.
Q07. Data members which are static (A) cannot be assigned a value (B) can only be used in static functions (C) cannot be defined in a Union (D) can be accessed outside the class
Q08. Declaration of a pointer reserves memory space (A) for the object. (B) for the pointer. (C) both for the object and the pointer. (D) none of these.
Q09. Consider the following statements char *ptr; ptr = hello; cout << *ptr; What will be printed? (A) first letter (B) entire string (C) it is a syntax error (D) last letter
Q10. In which case is it mandatory to provide a destructor in a class? (A) Almost in every class (B) Class for which two or more than two objects will be created (C) Class for which copy constructor is defined (D) Class whose objects will be created dynamically
Q11. The members of a class, by default, are (A) public (B) protected (C) private (D) mandatory to specify
Q12. Which of the statements is true in a protected derivation of a derived class from a base class? (A) Private members of the base class become protected members of the derived class (B) Protected members of the base class become public members of the derived class (C) Public members of the base class become protected members of the derived class (D) Protected derivation does not affect private and protected members of the derived class.
Q13. A pointer to the base class can hold address of (A) only base class object (B) only derived class object (C) base class object as well as derived class object (D) None of the above
Q14. If there is a pointer p to object of a base class and it contains the address of an object of a derived class and both classes contain a virtual member function abc(), then the statement p->abc(); will cause the version of abc() in the __________class to be executed. (A) Base Class (B) Derived class (C) Produces compile time error (D) Produces runtime error
Q15. A static function (A) should be called when an object is destroyed. (B) is closely connected with and individual object of a class. (C) can be called using the class name and function name. (D) is used when a dummy object must be created.
Q16. What is the output of the following program? #include void main() { char *ptr=abcd char ch; ch = ++*ptr++; cout<
Q17. A copy constructor is a member function that takes (A) no arguments (B) 1 argument (C) 2 arguments (D) an arbitrary no. of arguments
Q18. If we store the address of a derived class object into a variable whose type is a pointer to the base class, then the object, when accessed using this pointer.. (A) Continues to act like a derived class object. (B) Continues to act like a derived class object if virtual functions are called. (C) Acts like a base class object. (D) Acts like a base class, if virtual functions are called.
Q19. If a base class destructor is not virtual, then (A) It cannot have a function body. (B) It cannot be called. (C) It cannot be called when accessed from pointer. (D) Destructor in derived class cannot be called when accessed through a pointer to the base class.
Q20. Member functions, when defined within the class specification: (A) are always inline. (B) are not inline. (C) are inline by default, unless they are too big or too complicated. (D) are not inline by default.
Q21. Cross-out all the lines that will not compile in the main function of the following program: #include class A{ public: A(){} virtual int output() = 0; private: int i; }; class B: public A{ private: int j; }; class C{ public: int f(int a){return x*a;} protected: void setX(int a){x=a;} int getX(){return x;} private: int x; }; class D: public C{ private: int z; }; int main(){ A objA; B objB; C objC; D objD; C.setX(2); cout< D.setX(1); D.f(3); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
