C++ MCQs with answers Page - 118

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. Output of the program?
#include<iostream>
using namespace std;
int fun(int x = 0, int y = 0, int z)
{ return (x + y + z); }
int main()
{
cout << fun(10);
return 0;
}

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

A

Admin • 833.24K Points
Coach

Q. Output of following program?
#include <iostream>
using namespace std;
int fun(int=0, int = 0);
int main()
{
cout << fun(5);
return 0;
}
int fun(int x, int y)
{
return (x+y);
}

  • (A) Compiler Error
  • (B) 5
  • (C) 0
  • (D) 10

A

Admin • 833.24K Points
Coach

Q. Which of the following is true?

  • (A) Static methods cannot be overloaded.
  • (B) Static data members can only be accessed by static methods.
  • (C) Non-static data members can be accessed by static methods.
  • (D) Static methods can only access static members (data and methods)

A

Admin • 833.24K Points
Coach

Q. If a function is friend of a class, which one of the following is wrong?

  • (A) A function can only be declared a friend by a class itself.
  • (B) Friend functions are not members of a class, they are associated with it.
  • (C) Friend functions are members of a class.
  • (D) It can have access to all members of the class, even private ones.

A

Admin • 833.24K Points
Coach

Q. In C++, const qualifier can be applied to
1) Member functions of a class
2) Function arguments
3) To a class data member which is declared as static
4) Reference variables

  • (A) Only 1, 2 and 3
  • (B) Only 1, 2 and 4
  • (C) All
  • (D) Only 1, 3 and 4

A

Admin • 833.24K Points
Coach

Q. How to create a dynamic array of pointers (to integers) of size 10 using new in C++? Hint: We can create a non-dynamic array using int *arr[10]

  • (A) int *arr = new int *[10];
  • (B) int **arr = new int *[10];
  • (C) int *arr = new int [10];
  • (D) Not Possible

A

Admin • 833.24K Points
Coach

Q. Which of the following is true about new when compared with malloc:
1) new is an operator, malloc is a function
2) new calls constructor, malloc doesn’t
3) new returns appropriate pointer, malloc returns void * and pointer needs to typecast to appropriate type.

  • (A) 1 and 3
  • (B) 2 and 3
  • (C) 1 and 2
  • (D) All 1, 2 and 3

A

Admin • 833.24K Points
Coach

Q. Predict the output?
#include <iostream>
using namespace std;
class Test
{
int x;
Test()
{
x = 5;
} };
int main()
{
Test *t = new Test;
cout << t->x;
}

  • (A) Compiler Error
  • (B) 5
  • (C) Garbage Value
  • (D) 0

A

Admin • 833.24K Points
Coach

Q. Is it fine to call delete twice for a pointer?
#include<iostream>
using namespace std;
int main()
{
int *ptr = new int;
delete ptr;
delete ptr;
return 0;
}

  • (A) Yes
  • (B) No
  • (C) none
  • (D) all

A

Admin • 833.24K Points
Coach

Q. When the inheritance is private, the private methods in base class are __________ in the derived class (in C++).

  • (A) inaccessible
  • (B) accessible
  • (C) protected
  • (D) public

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