Explore topic-wise MCQs in C++ Programming.

This section includes 25 Mcqs, each offering curated multiple-choice questions to sharpen your C++ Programming knowledge and support exam preparation. Choose a topic below to get started.

1.

What is the output of this program?
#include <iostream>
using namespace std;
class N
{
public:
N(int k = 0){ _k = k;}
void fun()
{
cout << "Program Executed..."< }
private:
int _k;
};
int main()
{
N *ptr = 0;
ptr -> fun();
}

A. Program Executed...
B. Compilation Error
C. Runtime Error
D. Garbage value
E. None of these
Answer» B. Compilation Error
2.

What is the output of this program?
#include 
using namespace std;
int main()
{
int p = 3, q = 5, r = 13;
int *array[ ] = {&p, &q, &r};
cout << array[1];
return 0;
}

A. 5
B. 3
C. 13
D. Compilation Error
E. Random number
Answer» F.
3.

What will happen in this code?
int n = 50, m = 50;
int *ptr = &n, *ptr0 = &m;
ptr = ptr0;

A. ptr now points to m
B. m is assigned to n
C. ptr0 now points to n
D. n is assigned to m
E. None of these
Answer» B. m is assigned to n
4.

What is the output of this program?
#include 
using namespace std;
int main()
{
int array[] = {40, 15, 60, 17};
int *ptr = (array + 3);
cout << *array + 8;
return 0;
}

A. 40
B. 15
C. 60
D. 17
E. 48
Answer» F.
5.

What is the output of this program?
#include 
using namespace std;
int main ()
{
int num[5];
int * ptr;
ptr = num; *ptr = 12;
ptr++; *ptr = 21;
ptr = &num[2]; *ptr = 35;
ptr = num + 3; *ptr = 14;
ptr = num; *(ptr + 4) = 53;
for (int k = 0; k < 5; k++)
cout << num[k] << ",";
return 0;
}

A. 12,21,35,14,53,
B. 35,14,53,
C. 14,53,
D. 12,21,35,14
E. 12,21
Answer» B. 35,14,53,
6.

What is the output of this program?
#include 
using namespace std;
int main()
{
int array[] = {40, 15, 23, 71};
int *p = (array + 2);
cout << array;
return 0;
}

A. 40
B. 15
C. 23
D. 71
E. Address of arr
Answer» F.
7.

What is the output of this program?
#include 
using namespace std;
int fun(void *P);
int main()
{
char *S = "Interview Mania";
fun(S);
return 0;
}
int fun(void *P)
{
cout << P;
return 0;
}

A. Address of sting "Interview Mania"
B. Compilation Error
C. Runtime Error
D. Garbage Value
E. Interview Mania
Answer» B. Compilation Error
8.

What is the output of this program?
#include 
using namespace std;
int main()
{
int num = 10;
void *ptr = &num;
int *ptr0 = static_cast(ptr);
cout << *ptr0;
return 0;
}

A. 10
B. Compilation Error
C. Runtime Error
D. Garbage value
E. None of these
Answer» B. Compilation Error
9.

What is the output of this program?
#include 
using namespace std;
int main()
{
int *ptr;
void *vptr;
if (vptr == ptr)
{
cout << "Interview Mania";
}
return 0;
}

A. Interview Mania
B. Compilation Error
C. Runtime Error
D. Garbage value
E. None of these
Answer» B. Compilation Error
10.

What is the output of this program?
#include 
using namespace std;
void function(int p)
{
cout << p;
}
int main()
{
void (*num)(int);
num = &function;
(*num)( 3 );
num( 11 );
return 0;
}

A. 11
B. 3
C. 311
D. 113
E. None of these
Answer» D. 113
11.

What is the output of this program?
#include 
using namespace std;
int addition(int num1, int num2)
{
return num1 + num2 + 13;
}
int calculation(int num1, int num2, int (*funcall)(int, int))
{
return (*funcall)(num1, num2);
}
int main()
{
int n;
int (*plus)(int, int) = addition;
n = calculation(12, 20, plus);
cout << n;
return 0;
}

A. 45
B. 12
C. 13
D. 10
E. None of these
Answer» B. 12
12.

What is the meaning of the following declaration?
int(*p[10])();

A. p is pointer to function
B. p is pointer to such function which return type is array
C. p is pointer to array of function
D. p is array of pointer to function
E. None of these
Answer» E. None of these
13.

What is the output of this program?
#include 
using namespace std;
int function(int n, int m)
{
cout << n;
cout << m;
return 0;
}
int main(void)
{
int(*p)(char, int);
p = function;
function(11, 10);
p(12, 13);
return 0;
}

A. 11
B. 10
C. 12
D. 13
E. Compilation Error
Answer» F.
14.

What is the output of this program?
#include 
using namespace std;
int function(char, int);
int (*ptr) (char, int) = function;
int main()
{
(*ptr)('I', 6);
ptr(12, 6);
return 0;
}
int function(char n, int num)
{
cout << n << num;
return 0;
}

A. N66
B. 6N6
C. 66N
D. 126
E. None of these
Answer» B. 6N6
15.

What is the output of this program?
#include 
using namespace std;
int main()
{
char *p;
char S[] = "interviewMania";
p = S;
p += 5;
cout << p;
return 0;
}

A. InterviewMania
B. Mania
C. Interview
D. viewMania
E. None of these
Answer» E. None of these
16.

What will happen in this code?

A. ptr now points to m
B. m is assigned to n
C. ptr0 now points to n
D. n is assigned to m
E. None of these
Answer» B. m is assigned to n
17.

The void pointer can point to which type of objects?

A. float
B. double
C. int
D. All of above
E. None of these
Answer» E. None of these
18.

What we can t do on a void pointer?

A. pointer functions
B. pointer arithmetic
C. Both A and B
D. pointer static
E. None of these
Answer» C. Both A and B
19.

To which does the function pointer point to?

A. absolute variables
B. variable
C. constants
D. function
E. None of these
Answer» E. None of these
20.

which of the following can be passed in function pointers?

A. functions
B. variables
C. data types
D. All of above
E. None of these
Answer» B. variables
21.

What is the mandatory part to present in function pointers?

A. return values
B. data types
C. &
D. All of above
E. None of these
Answer» C. &
22.

Which is referred by pointers to member?

A. Non-static members of class objects
B. Referring to whole class
C. static members of class objects
D. All of above
E. None of these
Answer» B. Referring to whole class
23.

Which one of the following is not a possible state for a pointer.

A. point to a tye
B. zero
C. point one past the end of an object
D. hold the address of the specific object
E. None of these
Answer» B. zero
24.

Which is the best design choice for using pointer to member function?

A. Class
B. Structure
C. Interface
D. All of above
E. None of these
Answer» D. All of above
25.

What is the operation for .*?

A. It reduces the data size
B. It combines the first operand and the second operand
C. It separates the first operand and the second operand
D. All of above
E. None of these
Answer» C. It separates the first operand and the second operand