MCQ

C++ MCQ Questions and Answers – Part 10

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 character is used to terminate a structure?

A :

B }

C ;

D ;;

C
A semi-colon ‘;’ is used to terminate a structure. Example:

enum season
{  
    spring = 0, 
    summer = 6, 
    autumn = 9,
    winter = 11
};

 

 

2. A void pointer can point to what type of objects?

A int

B double

C float

D All the answers are true

D
Since it does not know the type of object it will point to, it can point to any type of object.

 

 
 

3. The pointer can point to any variable not declared with _____

A const

B volatile

C const and volatile

D static

C

 

 

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

A 35

B 15

C 27

D 15

B
Because the * operator has the highest priority, it is executed first, then the + operator will be executed.
 

 

 

5. What will happen when a structure is declared?

A It won’t allocate any memory

B It will allocate the memory

C It is declared and initialized

D None of the above

A
As long as the structure is declared, it will not be initialized. Therefore, it will not allocate any memory.

 

 
 

6. What is the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
	int x = 2, y = 3, z, w;
	z = x, y;
	w = (x, y);
	cout << z << ' ' << w;
	return 0;
}

A 2 3

B 3 2

C 2 2

D 3 3

A
The x value is stored in ‘z’ and in ‘w’, the y value is stored in ‘w’ because of the parenthesis.
 

 

 

7. What is the size of a generic pointer in C++ (on a 32 bits platform)?

A 2

B 4

C 8

D None of the above

B
The size of any pointer type is 4 bytes on 32-bit platforms.

 

 

8. What is the purpose of ‘p’ in the following statement?
int (*p[3]) ();

A p is a pointer to a function

B p is an array of pointers to a function

C p is a pointer to a function whose return type is an array

D p is a pointer to a function array

B
In the above statement, the variable p is an array, not a pointer.

 

 
 

9. A void pointer cannot point to ______

A class members in C++

B methods in C++

C All the answers are true

D None of the above

D

 

 

10. What is the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
	int *p1;
	void *p2;
	if (p1 == p2);
		cout << "equal";
	return 0;
}

A equal

B No output

C Runtime error

D Compilation error

A
The “void” pointer is easily convertible to another type, so the two pointers are equal.

 

 
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 *