C++ MCQs with answers Page - 145

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 = 5; int y = x++; cout << y;

  • (A) 5
  • (B) 6
  • (C) 0
  • (D) Error

A

Admin • 833.24K Points
Coach

Q. Which of the following is the correct way to declare a constant in C++?

  • (A) const int x = 10;
  • (B) int const x = 10;
  • (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 *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 constructor in C++?

  • (A) MyClass() { }
  • (B) void MyClass() { }
  • (C) int MyClass() { }
  • (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) 1
  • (B) 0
  • (C) 10
  • (D) 20

A

Admin • 833.24K Points
Coach

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

  • (A) ~MyClass() { }
  • (B) void ~MyClass() { }
  • (C) int ~MyClass() { }
  • (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) 1
  • (B) 0
  • (C) 10
  • (D) 20

A

Admin • 833.24K Points
Coach

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

  • (A) void MyClass::myFunction() { }
  • (B) void myFunction() { }
  • (C) MyClass::void myFunction() { }
  • (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) 1
  • (B) 0
  • (C) 10
  • (D) 20

A

Admin • 833.24K Points
Coach

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

  • (A) template <typename T> T myFunction(T a) { }
  • (B) template <class T> T myFunction(T a) { }
  • (C) Both A and B
  • (D) None of the above