Explore topic-wise MCQs in C++ Programming.

This section includes 48 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;
int main()
{
int num = 6;
int* ptr = &num;
cout << sizeof(ptr);
return 0;
}

A. 2
B. 4
C. 6
D. 8
E. Depends on compiler
Answer» B. 4
2.

What is the output of this program?
#include 
using namespace std;
void print (char * str)
{
cout << str << endl;
}
int main ()
{
const char * str = "Interview Mania";
print(const_cast (str) );
return 0;
}

A. Interview
B. Mania
C. Interview Mania
D. All of above
E. None of these
Answer» D. All of above
3.

What is the output of this program?
#include 
using namespace std;
int main()
{
int num = 11;
int & numref = num;
num++;
cout << "The value of num is " << numref;
return 0;
}

A. 12
B. 11
C. Garbage value
D. Compilation Error
E. Runtime Error
Answer» B. 11
4.

What is the output of this program?
#include 
using namespace std;
void swap(int &p, int &q);
int main()
{
int p = 5, q = 10;
swap(p, q);
cout << " In main " << p << q;
return 0;
}
void swap(int &p, int &q)
{
int temp;
temp = p;
p = q;
q = temp;
cout << "In swap " << p << q;
}

A. In swap 11 15
B. In main 11 15
C. Compilation Error
D. Runtime Error
E. In swap 11 15 In main 11 15
Answer» F.
5.

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

A. 0
B. 12
C. Compilation Error
D. Runtime Error
E. None of these
Answer» C. Compilation Error
6.

What is the output of this program?
#include <iostream>
using namespace std;
int main()
{
int num1, num2;
int* Res;
Res = &num1;
num1 = 150;
num2 = 100;
*Res = 150;
num2 = *Res;
cout << *Res << " " << num2;
return 0;
}

A. 200 200
B. 100 100
C. 150 150
D. Compilation Error
E. None of these
Answer» D. Compilation Error
7.

Which of the following statements is correct?Pointer to a reference and reference to a pointer both are valid.When we use reference, we are actually referring to a referent.

A. Only 2 is correct.
B. Only 1 is correct.
C. Both 1 and 2 are incorrect.
D. Both 1 and 2 are correct.
Answer» E.
8.

Which of the following statements is correct?Change a reference changes the referent.We can create an array of references.

A. Only 2 is correct.
B. Only 1 is correct.
C. Both 1 and 2 are incorrect.
D. Both 1 and 2 are correct.
Answer» C. Both 1 and 2 are incorrect.
9.

Which of the following statements is correct?A reference is not a constant pointer.A referenced is automatically de-referenced.

A. Only 2 is correct.
B. Only 1 is correct.
C. Both 1 and 2 are incorrect.
D. Both 1 and 2 are correct
Answer» B. Only 1 is correct.
10.

Which of the following statements is correct?Once the variable and the reference are linked they are tied together.Once the reference of a variable is declared another reference of that variable is not allowed.

A. Only 2 is correct.
B. Only 1 is correct.
C. Both 1 and 2 are incorrect.
D. Both 1 and 2 are correct.
Answer» C. Both 1 and 2 are incorrect.
11.

Which of the following statements is correct?Once a reference variable has been defined to refer to a particular variable it can refer to any other variable.A reference is not a constant pointer.

A. Only 2 is correct.
B. Only 1 is correct.
C. Both 1 and 2 are incorrect.
D. Both 1 and 2 are correct.
Answer» D. Both 1 and 2 are correct.
12.

Which of the following statement is correct about the program given below?

A. The program will print the output 10 21.
B. The program will print the output 10 20.
C. The program will print the output 11 21
D. The program will print the output 11 20.
Answer» C. The program will print the output 11 21
13.

Which of the following statement is correct about the program given below? #include int main() { int m = 2, n = 6; int &x = m++; int &y = n++; m = x++; x = m++; n = y++; y = n++; cout<< m << " " << n; return 0; }

A. The program will print output 3 7.
B. The program will print output 4 8.
C. The program will print output 5 9.
D. The program will print output 6 10.
Answer» E.
14.

Which of the following statement is correct about the program given below? #include int main() { int arr[] = {1, 2 ,3, 4, 5}; int &zarr = arr; for(int i = 0; i <= 4; i++) { arr[i] += arr[i]; } for(i = 0; i <= 4; i++) cout<< zarr[i]; return 0; }

A. The program will print the output 1 2 3 4 5.
B. The program will print the output 2 4 6 8 10.
C. The program will print the output 1 1 1 1 1.
D. It will result in a compile time error.
Answer» E.
15.

Which of the following statement is correct about the program given below? #include class IndiaBix { int x, y; public: void SetValue(int &a, int &b) { a = 100; x = a; y = b; Display(); } void Display() { cout<< x << " " << y; } }; int main() { int x = 10; IndiaBix objBix; objBix.SetValue(x, x); return 0; }

A. The program will print the output 100 10.
B. The program will print the output 100 100.
C. The program will print the output 100 garbage.
D. The program will print two garbage values.
Answer» C. The program will print the output 100 garbage.
16.

Which of the following statement is correct about the program given below? #include class IndiaBix { int x, y; public: void SetValue(int &xx, int &yy) { x = xx ++; y = yy; Display(); } void Display() { cout<< x << " " << y; } }; int main() { int x = 10; int &y = x; IndiaBix objBix; objBix.SetValue(x , y); return 0; }

A. The program will print the output 10 10.
B. The program will print the output 10 11.
C. The program will print the output 11 11.
D. The program will print the output 11 10.
Answer» C. The program will print the output 11 11.
17.

Which of the following statement is correct about the program given below? #include int main() { int m = 2, n = 6; int &x = m; int &y = n; m = x++; x = m++; n = y++; y = n++; cout<< m << " " << n; return 0; }

A. The program will print output 2 6.
B. The program will print output 3 7.
C. The program will print output 4 8.
D. The program will print output 5 9.
Answer» D. The program will print output 5 9.
18.

What will be the output of the following program? #include class BixTest { public: BixTest(int &x, int &y) { x++; y++; } }; int main() { int a = 10, b = 20; BixTest objBT(a, b); cout<< a << " " << b; return 0; }

A. 10 20
B. 11 21
C. Garbage Garbage
D. It will result in a compile time error.
Answer» C. Garbage Garbage
19.

What will be the output of the program given below? #include class BixBase { int x; public: BixBase(int xx = 0) { x = xx; } void Display() { cout<< x ; } }; class BixDerived : public BixBase { int y; public: BixDerived(int yy = 0) { y = yy; } void Display() { cout<< y ; } }; int main() { BixBase objBase(10); BixBase &objRef = objBase; BixDerived objDev(20); objRef = objDev; objDev.Display(); return 0; }

A. 0
B. 10
C. 20
D. Garbage-value
Answer» D. Garbage-value
20.

Which of the following statement is correct about the program given below? #include int main() { int x = 0; int &y = x; y = 5; while(x <= 5) { cout<< y++ << " "; x++; } cout<< x; return 0; }

A. The program will print the output 5 6 7 8 9 10.
B. The program will print the output 5 6 7 8 9 10 7.
C. The program will print the output 5 7.
D. It will result in a compile time error.
Answer» D. It will result in a compile time error.
21.

Which of the following statement is correct about the program given below? #include int x, y; class BixTest { public: BixTest(int xx = 0, int yy = 0) { x = xx; y = yy; Display(); } void Display() { cout<< x << " " << y << " "; } }; int main() { BixTest objBT(10, 20); int &rx = x; int &ry = y; ry = x; rx = y; cout<< rx--; return 0; }

A. The program will print the output 0 0 10.
B. The program will print the output 10 20 10.
C. The program will print the output 10 20 9.
D. It will result in a compile time error.
Answer» C. The program will print the output 10 20 9.
22.

Which of the following statement is correct about the program given below? #include class IndiaBix { int x, y; public: IndiaBix(int xx = 0, int yy = 0) { x = xx; y = yy; } void Display() { cout<< x << " " << y; } IndiaBix operator +(IndiaBix z) { IndiaBix objTemp; objTemp.x = x + z.x; objTemp.y = y + z.y; return objTemp; } }; int main() { IndiaBix objBix1(90, 80); IndiaBix objBix2(10, 20); IndiaBix objSum; IndiaBix &objRef = objSum; objRef = objBix1 + objBix2; objRef.Display(); return 0; }

A. It will result in a runtime error.
B. It will result in a compile time error.
C. The program will print the output 9 4.
D. The program will print the output 100 100.
Answer» E.
23.

Which of the following statement is correct about the program given below? #include class IndiaBix { int x, y; public: IndiaBix(int &xx, int &yy) { x = xx; y = yy; Display(); } void Display() { cout<< x << " " << y; } }; int main() { int x1 = 10; int &p = x1; int y1 = 20; int &q = y1; IndiaBix objBix(p, q); return 0; }

A. It will result in a compile time error.
B. The program will print the output 10 20.
C. The program will print two garbage values.
D. The program will print the address of variable x1 and y1.
Answer» C. The program will print two garbage values.
24.

Which of the following statement is correct about the program given below? #include struct Bix { short n; }; int main() { Bix b; Bix& rb = b; b.n = 5; cout << b.n << " " << rb.n << " "; rb.n = 8; cout << b.n << " " << rb.n; return 0; }

A. It will result in a compile time error.
B. The program will print the output 5 5 5 8.
C. The program will print the output 5 5 8 8.
D. The program will print the output 5 5 5 5.
Answer» D. The program will print the output 5 5 5 5.
25.

Which of the following statement is correct about the program given below? #include int BixFunction(int m) { m *= m; return((10)*(m /= m)); } int main() { int c = 9, *d = &c, e; int &z = e; e = BixFunction(c-- % 3 ? ++*d :(*d *= *d)); z = z + e / 10; cout<< c << " " << e; return 0; }

A. It will result in a compile time error.
B. The program will print the output 64 9.
C. The program will print the output 64 10.
D. The program will print the output 64 11.
Answer» E.
26.

Which of the following statement is correct about the program given below? #include class IndiaBix { int a, b, c; public: void SetValue(int x, int y ,int z) { a = x; b = y; c = z; } void Display() { cout<< a << " " << b << " " << c; } }; int main() { IndiaBix objBix; int x = 2; int &y = x; y = 5; objBix.SetValue(x, ++y, x + y); objBix.Display(); return 0; }

A. The program will print the output 5 6 10.
B. The program will print the output 6 6 10.
C. The program will print the output 6 6 12.
D. It will result in a compile time error.
Answer» C. The program will print the output 6 6 12.
27.

Which of the following statement is correct about the program given below? #include class IndiaBix { int x, y; public: void SetValue(int &xx, int &yy) { x = xx++; y = yy; cout<< xx << " " << yy; } }; int main() { int x = 10; int &y = x; IndiaBix objBix; objBix.SetValue(x , y); return 0; }

A. The program will print the output 10 10.
B. The program will print the output 10 11.
C. The program will print the output 11 10.
D. The program will print the output 11 11.
Answer» E.
28.

What will be the output of the following program? #include enum xyz { a, b, c }; int main() { int x = a, y = b, z = c; int &p = x, &q = y, &r = z; p = z; p = ++q; q = ++p; z = ++q + p++; cout<< p << " " << q << " " << z; return 0; }

A. 2 3 6
B. 4 4 7
C. 4 5 8
D. 3 4 6
Answer» C. 4 5 8
29.

Which of the following statement is correct about the program given below? #include class Bix { int x, y; public: Bix(int x, int y) { this->x = x; this->y = y; } void Display() { cout<< x << " " << y; } }; int main() { int x = 50; int &y = x ; Bix b(y, x); return 0; }

A. The program will print the output 50 50.
B. The program will print the two garbage values.
C. It will result in a compile time error.
D. The program will print nothing.
Answer» E.
30.

Reference is like a _____.

A. Pointer
B. Structure
C. Macro
D. Enum
Answer» B. Structure
31.

Which of the following statements is correct? An array of references is acceptable. We can also create a reference to a reference.

A. Only 1 is correct.
B. Only 2 is correct.
C. Both 1 and 2 are correct.
D. Both 1 and 2 are incorrect.
Answer» E.
32.

Which of the following statement is correct about the program given below? #include enum xyz { a, b, c }; int main() { int x = a, y = b, z = c; int &p = x, &q = y, &r = z; p = ++x; q = ++y; r = ++c; cout<< p << q << r; return 0; }

A. The program will print the output 1 2 3.
B. The program will print the output 2 3 4.
C. The program will print the output 0 1 2.
D. It will result in a compile time error.
Answer» E.
33.

Which of the following statements is correct? Pointer to a reference and reference to a pointer both are valid. When we use reference, we are actually referring to a referent.

A. Only 1 is correct.
B. Only 2 is correct.
C. Both 1 and 2 are correct.
D. Both 1 and 2 are incorrect.
Answer» D. Both 1 and 2 are incorrect.
34.

Which of the following statements is correct? A reference is not a constant pointer. A referenced is automatically de-referenced.

A. Only 1 is correct.
B. Only 2 is correct.
C. Both 1 and 2 are correct.
D. Both 1 and 2 are incorrect.
Answer» C. Both 1 and 2 are correct.
35.

Which of the following statement is correct about the program given below? #include int main() { int x = 10, y = 20; int *ptr = &x; int &ref = y; *ptr++; ref++; cout<< x << " " << y; return 0; }

A. The program will print the output 10 20.
B. The program will print the output 10 21.
C. The program will print the output 11 20.
D. The program will print the output 11 21.
Answer» C. The program will print the output 11 20.
36.

Which of the following statement is correct about the program given below? #include enum bix { a=1, b, c }; int main() { int x = c; int &y = x; int &z = x; y = b; cout<< z--; return 0; }

A. It will result in a compile time error.
B. The program will print the output 1.
C. The program will print the output 2.
D. The program will print the output 3.
Answer» D. The program will print the output 3.
37.

Which of the following statement is correct about the program given below? #include int main() { int x = 10; int &y = x; x = 25; y = 50; cout<< x << " " << --y; return 0; }

A. The program will print the output 25 49.
B. It will result in a compile time error.
C. The program will print the output 50 50.
D. The program will print the output 49 49.
Answer» E.
38.

Which of the following statement is correct about the program given below? #include int main() { int x = 10; int &y = x; x++; cout<< x << " " << y++; return 0; }

A. The program will print the output 11 12.
B. The program will print the output 12 11.
C. The program will print the output 12 13.
D. It will result in a compile time error.
Answer» C. The program will print the output 12 13.
39.

Which of the following statement is correct about the program given below? #include int i, j; class IndiaBix { public: IndiaBix(int x = 0, int y = 0) { i = x; j = x; Display(); } void Display() { cout<< j <<" "; } }; int main() { IndiaBix objBix(10, 20); int &s = i; int &z = j; i++; cout<< s-- << " " << ++z; return 0; }

A. The program will print the output 0 11 21.
B. The program will print the output 10 11 11.
C. The program will print the output 10 11 21.
D. The program will print the output 10 11 12.
Answer» C. The program will print the output 10 11 21.
40.

Which of the following statement is correct about the program given below? #include int main() { int x = 80; int &y = x; x++; cout << x << " " << --y; return 0; }

A. The program will print the output 80 80.
B. The program will print the output 81 80.
C. The program will print the output 81 81.
D. It will result in a compile time error.
Answer» B. The program will print the output 81 80.
41.

Which of the following statements is correct? We can return a global variable by reference. We cannot return a local variable by reference.

A. Only 1 is correct.
B. Only 2 is correct.
C. Both 1 and 2 are correct.
D. Both 1 and 2 are incorrect.
Answer» C. Both 1 and 2 are correct.
42.

A reference is declared using the _____ symbol.

A. &&
B. &
C. ||
D. !
Answer» C. ||
43.

Which of the following statements is correct? Once a reference variable has been defined to refer to a particular variable it can refer to any other variable. A reference is not a constant pointer.

A. Only 1 is correct.
B. Only 2 is correct.
C. Both 1 and 2 are correct.
D. Both 1 and 2 are incorrect.
Answer» E.
44.

Which of the following statements is correct? Change a reference changes the referent. We can create an array of references.

A. Only 1 is correct.
B. Only 2 is correct.
C. Both 1 and 2 are correct.
D. Both 1 and 2 are incorrect.
Answer» B. Only 2 is correct.
45.

Functions can be declared to return a reference type. There are reasons to make such a declaration/Which of the following reasons are correct? The information being returned is a large enough object that returning a reference is more efficient than returning a copy. The type of the function must be a R-value.

A. Only 1 is correct.
B. Only 2 is correct.
C. Both 1 and 2 are correct.
D. Both 1 and 2 are incorrect.
Answer» D. Both 1 and 2 are incorrect.
46.

Which of the following statement is correct about the references?

A. A reference must always be initialized within functions.
B. A reference must always be initialized outside all functions.
C. A reference must always be initialized.
D. Both A and C.
Answer» D. Both A and C.
47.

Which of the following statements is correct? Once the variable and the reference are linked they are tied together. Once the reference of a variable is declared another reference of that variable is not allowed.

A. Only 1 is correct.
B. Only 2 is correct.
C. Both 1 and 2 are correct.
D. Both 1 and 2 are incorrect.
Answer» B. Only 2 is correct.
48.

Which of the following statement is correct about the program given below? #include int main() { int x = 80; int y& = x; x++; cout << x << " " << --y; return 0; }

A. The program will print the output 80 80.
B. The program will print the output 81 80.
C. The program will print the output 81 81.
D. It will result in a compile time error.
Answer» E.