C++ MCQs with answers Page - 146

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. What is the output of the following code snippet? int x = 10; int *ptr = &x; cout << ptr;

  • (A) 10
  • (B) Address of x
  • (C) 0
  • (D) Error

A

Admin • 833.24K Points
Coach

Q. Which of the following is the correct way to define a static member variable in C++?

  • (A) static int x;
  • (B) int static x;
  • (C) Both A and B
  • (D) None of the above

A

Admin • 833.24K Points
Coach

Q. What is the output of the following code snippet? int x = 10; int y = 20; cout << (x > y ? x : y);

  • (A) 10
  • (B) 20
  • (C) 0
  • (D) Error

A

Admin • 833.24K Points
Coach

Q. Which of the following is the correct way to define a friend function in C++?

  • (A) friend void myFunction();
  • (B) void friend myFunction();
  • (C) Both A and B
  • (D) None of the above

A

Admin • 833.24K Points
Coach

Q. What is the output of the following code snippet? int x = 10; int y = 20; cout << (x + y);

  • (A) 10
  • (B) 20
  • (C) 30
  • (D) Error

A

Admin • 833.24K Points
Coach

Q. Which of the following is the correct way to define a virtual function in C++?

  • (A) virtual void myFunction();
  • (B) void virtual myFunction();
  • (C) Both A and B
  • (D) None of the above

A

Admin • 833.24K Points
Coach

Q. What is the output of the following code snippet? int x = 10; int y = 20; cout << (x - y);

  • (A) 10
  • (B) 20
  • (C) -10
  • (D) Error

A

Admin • 833.24K Points
Coach

Q. Which of the following is the correct way to define a pure virtual function in C++?

  • (A) virtual void myFunction() = 0;
  • (B) void virtual myFunction() = 0;
  • (C) Both A and B
  • (D) None of the above

A

Admin • 833.24K Points
Coach

Q. What is the output of the following code snippet? int x = 10; int y = 20; cout << (x * y);

  • (A) 10
  • (B) 20
  • (C) 200
  • (D) Error

A

Admin • 833.24K Points
Coach

Q. Which of the following is the correct way to define a namespace in C++?

  • (A) namespace MyNamespace { }
  • (B) namespace { MyNamespace }
  • (C) Both A and B
  • (D) None of the above

Add MCQ in this Category

If you want to share an MCQ question in this category, it's a great idea! It will be helpful for many other students using this website.

Share Your MCQ