C++ MCQs with answers Page - 155

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. Which of the following is the correct way to allocate memory dynamically for an integer in C++?

  • (A) new int;
  • (B) malloc(int);
  • (C) allocate int;
  • (D) int new();

A

Admin • 833.24K Points
Coach

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

  • (A) object->function();
  • (B) object.function();
  • (C) function(object);
  • (D) object.function();

A

Admin • 833.24K Points
Coach

Q. Which of the following C++ features allows a class to inherit from another class?

  • (A) Overloading
  • (B) Abstraction
  • (C) Inheritance
  • (D) Encapsulation

A

Admin • 833.24K Points
Coach

Q. What does the 'sizeof' operator in C++ return?

  • (A) The size of a variable in bytes
  • (B) The number of elements in an array
  • (C) The size of the stack
  • (D) The size of the data type

A

Admin • 833.24K Points
Coach

Q. Which C++ keyword is used to exit from a loop or switch statement?

  • (A) continue
  • (B) break
  • (C) exit
  • (D) return

A

Admin • 833.24K Points
Coach

Q. Which of the following statements is correct about constructors in C++?

  • (A) A constructor has no return type.
  • (B) A constructor is called when an object is created.
  • (C) A constructor can have parameters.
  • (D) All of the above

A

Admin • 833.24K Points
Coach

Q. What will be the output of the following code?

int a = 5;
int b = 2;
cout << a / b;

  • (A) 2.5
  • (B) 2
  • (C) 1
  • (D) Error

A

Admin • 833.24K Points
Coach

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

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

A

Admin • 833.24K Points
Coach

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

  • (A) void myFunction(int x = 10) { }
  • (B) void myFunction(int 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 >>= 1);

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

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