C++ MCQs with answers Page - 103

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. When allocating memory dynamically in C++, the new operator returns the value _________ if the memory allocation fails.

  • (A) False
  • (B) NULL
  • (C) Zero
  • (D) None of the above

A

Admin • 833.24K Points
Coach

Q. We can create objects of type ‘abstract class’?

  • (A) True
  • (B) False
  • (C) ---
  • (D) ---

A

Admin • 833.24K Points
Coach

Q. The default value of a static variable is _____.

  • (A) 1
  • (B) 0
  • (C) Depends on the compiler
  • (D) None of the above

A

Admin • 833.24K Points
Coach

Q. What is the output of the following C++ code?

Code:
#include<iostream> 
using namespace std; 
  
int a = 55; 
void fun() 
{ 
    int a = 20; 
    { 
        int a = 10; 
        cout << ::a << endl;  
    } 
} 
  
int main() 
{ 
    fun(); 
    return 0; 
}
  • (A) 10
  • (B) 20
  • (C) 55
  • (D) None of the above

A

Admin • 833.24K Points
Coach

Q. Which class functions are called inline functions?

  • (A) All functions declared inside a class
  • (B) All functions defined outside the class of
  • (C) All functions defined inside or with the keyword inline
  • (D) All functions accessing static members of the class

A

Admin • 833.24K Points
Coach

Q. The object is created in _________

  • (A) A class
  • (B) Constructor
  • (C) Destructor
  • (D) Attributes

A

Admin • 833.24K Points
Coach

Q. What is the output of the following C++ code?

Code:
#include<iostream>

using namespace std;

class Point {
private:
    int x;
    int y;
public:
    Point(int a, int b);
};

Point::Point(int a = 0, int b = 0)  {
    x = a;
    y = b;
    cout << "Constructor called";
}
  
int main()
{
   Point p1, *p2;
   return 0;
}
  • (A) Displays “Constructor called” only once.
  • (B) Displays “Constructor called” twice.
  • (C) Does not display anything.
  • (D) Compilation error

A

Admin • 833.24K Points
Coach

Q. What is the output of the following C++ program?

Code:
#include <iostream>

using namespace std;

int main ( )
{
  static double i;
  i = 15;
  cout << sizeof(i);
 return 0;
}
  • (A) 2
  • (B) 4
  • (C) 8
  • (D) 14

A

Admin • 833.24K Points
Coach

Q. Static variable must be declared in public section of the class.

  • (A) True
  • (B) False
  • (C) ---
  • (D) ---

A

Admin • 833.24K Points
Coach

Q. By default, if a function with minimum lines of code is declared and defined inside the class becomes Inline function

  • (A) True
  • (B) False
  • (C) ---
  • (D) ---

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