MCQ

C++ MCQ Questions and Answers – Part 11

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. Identify the type of variables.
typedef char* CHAR;
CHAR a,b;

A CHAR*

B CHAR

C char

D char*

D
The statement makes CHAR a synonym for char *.

 

 
 

2. What is the output of the following C++ code?
#include <iostream>
using namespace std;
enum letter 
{
	A = 20, B, C
};
int main()
{
  cout << A << B << C;
  return 0;
}

A 202020

B 202122

C 222120

D None of the above

B
The default value for enum types is 0 (which is by default the first element of the enumeration). In the example above, the user assigns the value 20 to A, the other members of the enumeration automatically increment by 1 relative to the previous one. Here is the output of the above program :
 

 

 

3. What is the output of the following C++ code?
#include <iostream>
using namespace std;
enum Jour {
	MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
};
int main()
{
	cout << MONDAY << TUESDAY << WEDNESDAY << THURSDAY << FRIDAY;
	return 0;
}

A 43210

B 01235

C 01234

D 01435

C

 

 

4. What is the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
	int i, j;
	i = 1;
	j = (i++, i + 10, 9 + i);
	cout << j;
	return 0;
}

A 10

B 2

C 11

D 20
 

 
C
i starts with the value 1.
i is then incremented to 2.
Next, i is added to 10.
Finally, i (still containing 2) is added to 9, giving the result 11.

 

 

5. How many instruction sequences are there in C++?

A 2

B 3

C 4

D 5

D
There are five sequences of instructions.

  • Preprocessor instructions
  • Comments
  • Declarations
  • Declarations of functions
  • Executable instructions.

 

 

6. The goto destination for the label is identified by __

A $

B @

C %

D :

D
The colon : is used at the end of the labels.
 

 

 

7. What is the output of the following C++ code?
#include <iostream>
using namespace std;
int main ()
{
	int i;
	for (i = 7; i > 0; i--)
	{
		cout << i;
		if (i == 5)
		break;
	}
	return 0;
}

A 76

B 7654

C 765

D 5

C
In the above program, we display the numbers in reverse order, but by using the break statement, we stopped the loop on i = 5.
 

 

 

8. What is the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
	int x = 2, v;
	void *p = &x;
	double y = 3;
	p = &y;
	v = x + y;
	cout << v << ', ' << p;
	return 0;
}

A Display 5, then the memory address

B Displays the memory address

C Display 5

D None of the above
 

 
A
In the above program, we store the address of y in the pointer p, then we sum x and y which gives 5, and finally we display the result.
 

 

 

9. How many comment types are there in C++?

A 1

B 2

C 3

D 4

B
There are two types of comments in C++. Single line comments use a double slash //. Multi-line comments use /* … */.

 

 

10. What is the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
	int n = 5;
	for ( ; ;)
	cout << n;
	return 0;
}

A Error

B 5

C Display 5 infinitely

D None of the above

C
There is no condition in the “for” loop, so it will be an infinite loop.

 

 
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 *