MCQ

C++ MCQ Questions and Answers – Part 1

Multiple choice questions and answers (MCQs) on C++ to prepare for exams, tests, and certifications. These questions are taken from a real written exam and some parts are taken from an interview. So you will find questions on basic techniques such as Variables, Operators, Conditional Statement, Functions, and more. This quiz will easily prepare anyone to pass their online test.
 

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

A $

B *

C %

D &

D
The & operator is called the “Address Operator” and is used to access the address of a variable. Example: cout << &age
 

 

 

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

A $my_var

B 2my_var

C MYVAR_9658

D 2MYVAR

C
The rules for writing an identifier are as follows:

  • Can contain only lowercase/uppercase letters, numbers or underscores (_)
  • Should start with a non-numeric character
  • Should not contain any special characters like $, @, !, %, etc.

 

 
 

3. What is the output of the following C++ program?
#include <iostream>

using namespace std;

int main ( )
{
	static double i;
	i = 15;
	cout << sizeof(i);
 return 0;
}

A 2

B 4

C 8

D 15

C
Size of type double is 8.
 

 

 

4. 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]

C
C++ uses quotation marks to include a user-defined header file. The correct syntax is #include "myfile".

 

 

5. Who created C++?

A Rasmus Lerdorf

B Bjarne Stroustrup

C James Gosling

D Ken Thompson

B
Bjarne Stroustrup is the creator of C++ in 1979 at AT&T Bell Labs.

 

 
 

7. What is the output of the following C++ program?
#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

B
In the above program, the integer is converted to a float. So the result of n1 and n2 is float. And it returns the size of the float.
 

 

 

8. Which of the following escape sequences represents a tab?

A \a

B \r

C \t \r

D \t

D
\t is used to represent a tab which means a set of empty spaces in a line.

 

 

9. Which of the following escape sequence represents the carriage return?

A \r

B \n

C \n \r

D \t

A
\r is used to represent the carriage return, which means to move the cursor to the beginning of the next line.

 

 

10. Which of the following used to write a comment in C++?

A // comment

B Both are comments // comment 1 or /* comment 2 */

C /* comment */

D // comment */

B
Both methods are used to write comments in C++ programming. // is used for single line comments and /*…*/ is used for multi-line comments.

 

 
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *