C++ MCQ Questions and Answers – Part 7

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. Evaluate the following expression :
(false && true) || false || true

A Compilation error

B 0

C False

D 1

The given expression is equivalent to: [(false AND True) OR false OR true]. We have logical OR, so if one of the expressions is true, then the whole expression will be true and since we have the last value as true, the answer of the expression is “True”.



2. Which of the following codes will display an error during compilation?

Code 1 :

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
	cout << "Welcom to StackHowTo";
	return 0;


Code 2 :

#include <iostream>
int main(int argc, char const *argv[])
	std::cout << "Welcom to StackHowTo";
	return 0;

A Code 1 and Code 2

B Only code 1

C Only code 2

D Neither code 1 nor code 2

Both codes do not show errors, because both are syntactically correct because in the first code we included “namespace std” and in the second we used the scope resolution operator to resolve the conflict.


3. Which of the following gives the memory address of the first element of the array?

A arr[0];

B arr[1];

C arr(2);

D arr;


To get the address of the nth index of an array, we use the following syntax:
(arr + n). So, as we need the address of the first index, we will use (arr + 0) equivalent to arr.



4. What is the result of the following C++ program?
#include <stdio.h>

using namespace std;

int main ()
	int arr[] = {0, 2, 4, 2, 1};
	int n, s = 0;
	for (n = 0; n < 6; n++) {
		s += arr[n];
	cout << s;
	return 0;

A 8

B 10

C 9

D None of the above

We have added up all the elements in the array. The total number of elements in the array is 5, but our “for” loop will go beyond 5 and add a random value.


5. What will happen in this code?
int x = 10, y = 20;
int *p = &x, *q = &y;
p = q;

A y is assigned to x

B p now points to y

C x is assigned to y

D q now points to x

Reference assignment changes the object to which the reference is linked.



6. What is the output of the following code?
#include <iostream>
using namespace std;
int main()
	char c = 65;
	cout << c;
	return 0;





The literal value for 65 is A. Therefore, the code will display the character A.



7. What is the output of the following code?
#include <iostream>
using namespace std;
int main()
   char *p;
   char str[] = "StackHowTo";
   p = str;
   p += 5;
   cout << p;
  return 0;

A StackHowTo

B Stack

C HowTo



The pointer p points to the string “HowTo”. So it displays “HowTo”.



8. Which of the following will not return a value?

A null

B void

C empty

D free

Since “void” represents an empty set of values, nothing will be sent.



9. What does the following statement mean?
void a;

A Variable a is of type void

B a is an object of type void

C Declares a variable with the value a

D Report an error

This reports an error :

The void type is a type used as a return type for functions that return no value.



10. Select the wrong option?

A void is used when the function does not return a value

B void is also used when the value of a pointer is null

C void is used as a base type for pointers to objects of unknown type

D void is a special type



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 *