C++ MCQs with answers Page - 14

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. Following is the invalid inclusion of a file to the current program. Identify it

  • (A) #include <file>
  • (B) #include "file"
  • (C) #include < file
  • (D) All of the above are invalid

A

Admin • 833.24K Points
Coach

Q. Does both the loops in the following programs prints the correct string length?

Code:
#include<iostream>

using namespace std;
main() {
   int i;
   
   char s[] = "hello";

   for(i=0; s[i]; ++i);
      cout<<i<<endl;

   i=0; 
   
   while(s[i++]);
      cout<<i;
}
  • (A) Yes, both the loops prints the correct length
  • (B) Only for loop prints the correct length
  • (C) Only while loop prints the correct length
  • (D) Compile error in the program.

A

Admin • 833.24K Points
Coach

Q. Which of the followings is/are not a manipulator/s ?

1. flush
2. base
3. ends
4. oct
5. bin
6. skipws

  • (A) Only 1, 6
  • (B) Only 1,4,6
  • (C) Only 1,3,6
  • (D) Only 2,5

A

Admin • 833.24K Points
Coach

Q. If default constructor is not defined, then how the objects of the class will be created?

  • (A) The compiler will generate error
  • (B) Error will occur at run-time.
  • (C) Compiler provides its default constructor to build the object.
  • (D) None of these

A

Admin • 833.24K Points
Coach

Q. Which of the following operators is called “Address operator”?

  • (A) $
  • (B) *
  • (C) %
  • (D) &

A

Admin • 833.24K Points
Coach

Q. Which of the following is a correct identifier in C++?

  • (A) $my_var
  • (B) 2my_var
  • (C) MYVAR_9658
  • (D) 2MYVAR

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
  • (A) 2
  • (B) 4
  • (C) 8
  • (D) 15

A

Admin • 833.24K Points
Coach

Q. What is the correct syntax for including a user-defined header file in C++?

  • (A) #include <myfile.h>
  • (B) #include <myfile>
  • (C) #include "myfile"
  • (D) #include [myfile]

A

Admin • 833.24K Points
Coach

Q. Who created C++?

  • (A) Rasmus Lerdorf
  • (B) Bjarne Stroustrup
  • (C) James Gosling
  • (D) Ken Thompson

A

Admin • 833.24K Points
Coach

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

Code:
#include <iostream>
using namespace std;
int main()
{
  int n1 = 10;
  float n2 = 10;
  cout << sizeof(n1 + n2);
 return 0;
}
  • (A) 2
  • (B) 4
  • (C) 6
  • (D) 8

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