C++ MCQs with answers Page - 156

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 define a function with multiple default arguments in C++?

  • (A) void myFunction(int x = 10, int y = 20) { }
  • (B) void myFunction(int x, int y = 20) { }
  • (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 function with a variable number of arguments using initializer_list in C++?

  • (A) void myFunction(std::initializer_list<int> args) { }
  • (B) void myFunction(int... args) { }
  • (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 function with a lambda expression in C++?

  • (A) auto myFunction = [](int x) { return x * x; };
  • (B) void myFunction(int x) { return x * 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 function with a trailing return type in C++?

  • (A) auto myFunction(int x) -> int { return x * x; }
  • (B) int myFunction(int x) { return x * x; }
  • (C) Both A and B
  • (D) None of the above

A

Admin • 833.24K Points
Coach

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

  • (A) void myFunction() noexcept { }
  • (B) void 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 ? 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 function with a deleted definition in C++?

  • (A) void myFunction() = delete;
  • (B) void myFunction() { }
  • (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