C++ MCQs with answers Page - 77

Here, you will find a collection of MCQ questions on C++. Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 833.24K Points
Coach

Q. Standard input-output stream is in c++:

  • (A) Cout
  • (B) Cin
  • (C) Both A & B
  • (D) None of the above

A

Admin • 833.24K Points
Coach

Q. C++ contains _________ numbers of keywords:

  • (A) 23
  • (B) 56
  • (C) 52
  • (D) 65

A

Admin • 833.24K Points
Coach

Q. Static variable in a class is initialized when:

  • (A) First object of the class is created
  • (B) With the runtime
  • (C) After calling the function
  • (D) All of these

A

Admin • 833.24K Points
Coach

Q. Static variable declared in a class are also called:

  • (A) Instance variable
  • (B) Class variable
  • (C) Local variable
  • (D) All of these

A

Admin • 833.24K Points
Coach

Q. Exception handler are declared with _______ keywords:

  • (A) Catch
  • (B) Finally
  • (C) Throw
  • (D) Try

A

Admin • 833.24K Points
Coach

Q. A friend class can access ____________________ members of other class in which it is declared as friend.

  • (A) public
  • (B) private
  • (C) protected
  • (D) Both B and C

A

Admin • 833.24K Points
Coach

Q. A friend function can be

  • (A) A method of another class
  • (B) A global function
  • (C) Both A and B
  • (D) None of the above

A

Admin • 833.24K Points
Coach

Q. What will be output for the followiing code?

Code:
#include <iostream>
class A { 
private: 
    int a; 
  
public: 
    A() { a = 0; } 
    friend class B; // Friend Class 
}; 
  
class B { 
private: 
    int b; 
  
public: 
    void showA(A& x) 
    { 
         
        std::cout << ""A::a="" << x.a; 
    } 
}; 
  
int main() 
{ 
    A a; 
    B b; 
    b.showA(a); 
  
 }
  • (A) A::0
  • (B) a=0
  • (C) A
  • (D) A::a=0

A

Admin • 833.24K Points
Coach

Q. What will be output for the following code?

Code:
class Box
{
 int capacity;
   public:
 void print();
 friend void show();
 bool compare();
 friend bool lost();
};
  • (A) 1
  • (B) 2
  • (C) 3
  • (D) 4

A

Admin • 833.24K Points
Coach

Q. Which keyword is used to represent a friend function?

  • (A) Friend_func
  • (B) friend_func
  • (C) Friend
  • (D) friend