Explore topic-wise MCQs in C++ Programming.

This section includes 72 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 
using namespace std;
int main()
{
char ch = 'M';

cout<< ch;
return 0;
}

A. Compilation Error
B. Runtime Error
C. M
D. All of above
E. None of these
Answer» D. All of above
2.

What will be the output of this program?
#include 
using namespace std;
int main()
{
int P = 20;
cout << "Given integer 'P' with 'true' :" << P && true;
return 0;
}

A. Given integer 'P' with 'true' :20
B. Given integer 'P' with 'true' :0
C. Given integer 'P' with 'true' :2
D. All of above
E. None of these
Answer» B. Given integer 'P' with 'true' :0
3.

What is the output of the following program?
#include 
using namespace std;
int main()
{
float n = 143.0f;
cout << n << endl;
return 0;
}

A. 143.0f
B. Compilation Error
C. Runtime Error
D. 143
E. None of these
Answer» E. None of these
4.

What is the output of this program?
#include 
#include
using namespace std;
int main()
{
cout << setprecision(17);
double n = 0.2;
cout << n << endl;
return 0;
}

A. 0.20000000000000001
B. 0.2000000001
C. 0.200
D. 2.20000000000000001
E. None of these
Answer» B. 0.2000000001
5.

What is the output of this program?
#include 
using namespace std;
int main()
{
float n1 = 10.1;
double n2 = 10.1;
if (n1 == n2)
cout << "Interview";
else
cout << "Mania";
return 0;
}

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

What would be the output of the following program (in 32-bit systems)?
#include 
using namespace std;
int main()
{
cout << sizeof(char);
cout << " "<< sizeof(int);
cout << " "<< sizeof(float);
return 0;
}

A. 1 4 4
B. 4 4 1
C. 4 1 4
D. Garbage value
E. None of these
Answer» B. 4 4 1
7.

What is the output of the following program?
#include 
using namespace std;
int main()
{
int p = 10;
float q;
cout << sizeof(++p + q);
cout << " "<

return 0;
}

A. 10 2
B. 10 4
C. 2 10
D. 10 0
E. 4 10
Answer» F.
8.

What is the output of the following program?
#include 
using namespace std;
int main()
{
int n = 0x10 + 030 + 50;
cout << sizeof(n)< return 0;
}

A. 0x10 + 030 + 50
B. 030 + 50
C. 0x10 + 030
D. Depends on compiler
E. Garbage
Answer» E. Garbage
9.

What is the output of this program?
#include 
using namespace std;
int main()
{
void num0 = 15, num1 = 16;
int num2;
num2 = num0 + num1;
cout << num2;
return 0;
}

A. 31
B. Runtime Error
C. Compile time Error
D. All of above
E. None of these
Answer» D. All of above
10.

What does the following statement mean?
void a;

A. declares a variable with value a
B. flags an error
C. a is an object of type void
D. variable a is of type void
E. None of these
Answer» C. a is an object of type void
11.

What is the output of this program?
#include 
using namespace std;
int main()
{
int k;
enum Month {
January = 1, February ,March, April, May, June, July, August, September, October, November, December
};
for (k = April; k <= September; k++)
cout << k;
return 0;
}

A. 456789
B. 0123456789101112
C. 0123456
D. 89101112
E. Compilation Error
Answer» B. 0123456789101112
12.

What constant defined in header returns the number of bits in a char?

A. SIZE_CHAR
B. CHAR_SIZE
C. CHAR_BIT
D. BIT_CHAR
E. None of these
Answer» D. BIT_CHAR
13.

What is the output of this program?
#include 
using namespace std;
int main()
{
float num0 = 10.6;
double num1 = 10.6;
if (num0 == 10.6f)
cout << "Interview";
else
cout << "Mania";
return 0;
}

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

Pick the right option
Statement (i) Global values are not initialized by the stream.
Statement (ii) Local values are implicitly initialised to 0.

A. Statement (i) is true, Statement (i) is false
B. Statement (i) is true, Statement (ii) is false
C. Both are true
D. Both are false
E. None of these
Answer» E. None of these
15.

Which of the given statements are false.
(i). extern int func;
(ii). extern int func2(int,int);
(iii). int func2(int,int);
(iv). extern class foo;

A. (ii), (iii) and (iv)
B. (iii) and (iv) only
C. (ii) and (iii) only
D. only (iv)
E. None of these
Answer» E. None of these
16.

Pick the right option
Statement (i) A definition is also a declaration.
Statement (ii) An identifier can be declared just once.

A. Statement (ii) is true, Statement (i) is false
B. Statement (i) is true, Statement (ii) is false
C. Both are true
D. Both are false
E. None of these
Answer» B. Statement (i) is true, Statement (ii) is false
17.

What is the output of this program?
#include 
using namespace std;
int main()
{
int p = 15;
if (p < 13) {
for (k = 0; k < 12; k++)
cout << k;
}
else {
cout << k;
}
return 0;
}

A. Compilation Error
B. Runtime Error
C. Garbage Value
D. All of above
E. None of these
Answer» B. Runtime Error
18.

Choose the correct option.
 (i) extern int k;
(ii0 int k;

A. (i) declares and defines k, (ii) declares k
B. both (i) and (ii) declare k
C. (i) declares k, (ii) declares and defines k
D. (i) declares the variable k and (ii) defines k
E. None of these
Answer» D. (i) declares the variable k and (ii) defines k
19.

What is the output of this program?
#include 
using namespace std;
int main()
{
enum channel {hotstar, zeetv, max};
enum symbol {anamol, hotstar};
int k = 0;
for (k = hotstar; k <= zeetv; k++) {
cout << k;
}
return 0;
}

A. Compilation Error
B. Runtime Error
C. Garbage Value
D. hotstar
E. None of these
Answer» B. Runtime Error
20.

What is the output of this program?
#include 
using namespace std;
enum Gender {
male, female, transgender
};
int main()
{
cout << male<< female<< transgender;
return 0;
}

A. male
B. female
C. transgender
D. All of above
E. 012
Answer» F.
21.

What is the output of this program?
#include 
using namespace std;
enum test
{
p = 20, q, r
};
int main()
{
cout << p < return 0;
}

A. 20 21
B. 21 22
C. 20 21 22
D. 20 22
E. None of these
Answer» D. 20 22
22.

What is the output of this program?
#include 
using namespace std;
enum boy
{
num = 20
};
int main()
{
int age = 100;
age /= num;
cout << "If you were boy, you would be " << age << endl;
return 0;
}

A. If you were boy, you would be 5
B. If you were boy, you would be 0
C. If you were boy, you would be 10
D. All of above
E. None of these
Answer» B. If you were boy, you would be 0
23.

What is the value of the following 8-bit integer after all statements are executed?
int a = 5;
a = a << 6;
a = a >> 6;

A. Implementation defined
B. -1
C. 127
D. 1
E. None of these
Answer» B. -1
24.

What will be output of this function?
#include 
using namespace std;
int main()
{
register int p = 15;
int *ptr = &p;
cout << *ptr;
return 0;
}

A. Compilation Error
B. Runtime Error
C. 15
D. 10
E. None of these
Answer» D. 10
25.

What will be output of this program?
#include 
using namespace std;
int main()
{
int num = 5;
int num0 = num / -10;
int num1 = num % -10;
cout << num0 << " "<< num1;
return 0;
}

A. Compilation Error
B. Runtime Error
C. 0 5
D. 5 0
E. None of these
Answer» D. 5 0
26.

What is the output of the following program?
#include
using namespace std;
int main()
{
int a = -10;
unsigned int b = 20;

if(a > b)
{
cout << "a is greater";
}
else
{
cout << "b is greater";
}
return 0;
}

A. 10
B. 20
C. a is greater
D. b is greater
E. None of these
Answer» D. b is greater
27.

Choose the right option
string* p, q;

A. q is a pointer to a string, p is a string
B. both p and q are pointers to string types
C. p is a pointer to a string, q is a string
D. All of above
E. None of these
Answer» D. All of above
28.

Identify the incorrect statements.
 int num = 23;
Statement (i): int *ptr = &(num + 2);
Statement (ii): int *ptr2 = &num;
Statement (iii): &&num = 50;

A. Statement (ii) and (iii) are wrong
B. Statement (i) and (iii) are wrong
C. Statement (i) and (ii) are wrong
D. All the three are wrong
E. None of these
Answer» C. Statement (i) and (ii) are wrong
29.

What is the output of this program?
#include 
using namespace std;
void Output()
{
static int p = 1;
int k;
for(k=p; k<=3; k++)
{
p++;
cout << p;
}
}
int main()
{
Output();
Output();
Output();
return 0;
}

A. 0123
B. 123
C. 234
D. 012345
E. 01234
Answer» D. 012345
30.

What will be the output of this program?
#include
using namespace std;
int main()
{
char ch = 65;
cout<< ch;
return 0;
}

A. 0
B. 65
C. A
D. All of above
E. None of these
Answer» D. All of above
31.

What is the value of the bool?
bool is_int(100.05)

A. 0
B. 1
C. True
D. False
E. None of these
Answer» E. None of these
32.

Select the right option.
Given the variables a, b are of char type and c, d, e are of int type
i. e = (c * d) / (c + d);
ii. e = (a * b) / (c + d);

A. i is false and ii is true
B. i is true but ii is false
C. both i and ii are false
D. both i and ii are true
E. None of these
Answer» E. None of these
33.

Evaluate the following
(false && true) || false || true

A. true
B. false
C. 0
D. 1
E. None of these
Answer» E. None of these
34.

Which of the following statements are true?
int n(float)

A. n is a function taking an argument of type float and returning an integer
B. n is a function of type float
C. n is a function taking an argument of type int and returning a floating point number
D. All of above
E. None of these
Answer» B. n is a function of type float
35.

What is the value of p?
#include 
using namespace std;
int main()
{
int res;
bool p = false;
bool q = true;
int num0 = 15;
int num1 = 10;
res = ((num0 | num1) + (p + q));
cout << res;
return 0;
}

A. 16
B. 15
C. 10
D. All of above
E. None of these
Answer» B. 15
36.

What is the output of the following program?
#include 
using namespace std;

int fun(int n, int m)
{
if (n > m)
return n;
else
return m;
}

main()
{
int num0 = 6, num1 = 12;
int res;
bool x = true;
bool y = fun(num0, num1);
res =((num0 * num1) + (x + y));
cout << res;
}

A. 6
B. 12
C. 74
D. 50
E. None of these
Answer» D. 50
37.

What would be the output of the following program (in 32-bit systems)?

A. 1 4 4
B. 4 4 1
C. 4 1 4
D. Garbage value
E. None of these
Answer» B. 4 4 1
38.

The size of an object or a type can be determined using which operator?

A. sizeof
B. malloc
C. calloc
D. malloc
E. None of these
Answer» B. malloc
39.

Which of the following will not return a value?

A. void
B. free
C. null
D. empty
E. None of these
Answer» D. empty
40.

Which variable does equals in size with enum variable?

A. string variable
B. int variable
C. float variable
D. All of above
E. None of these
Answer» C. float variable
41.

What will happen when defining the enumerated type?

A. it will not allocate memory to its variables
B. it will not allocate memory
C. it will allocate memory
D. All of above
E. None of these
Answer» C. it will allocate memory
42.

To which of these enumerators can be assigned?

A. negative
B. enumerator
C. integer
D. All of above
E. None of these
Answer» E. None of these
43.

In which type do the enumerators are stored by the compiler?

A. integer
B. float
C. string
D. All of these
E. None of these
Answer» B. float
44.

Can two functions declare variables(non static) with the same name.

A. Yes
B. No
C. No, it gives a runtime error
D. Yes, but not a very efficient way to write programs
E. None of these
Answer» E. None of these
45.

Which of the given statements are false.

A. (ii), (iii) and (iv)
B. (iii) and (iv) only
C. (ii) and (iii) only
D. only (iv)
E. None of these
Answer» E. None of these
46.

Pick the right option

A. Statement (ii) is true, Statement (i) is false
B. Statement (i) is true, Statement (ii) is false
C. Both are true
D. Both are false
E. None of these
Answer» B. Statement (i) is true, Statement (ii) is false
47.

Which is correct with respect to size of the data types?

A. char < int < double
B. char < int < float
C. int < char > float
D. char > int < float
E. None of these
Answer» B. char < int < float
48.

Which is used to indicate single precision value?

A. L or l
B. F or f
C. Neither F or for L or l
D. Either F or for L or l
E. None of these
Answer» C. Neither F or for L or l
49.

Choose the right option

A. q is a pointer to a string, p is a string
B. both p and q are pointers to string types
C. p is a pointer to a string, q is a string
D. All of above
E. None of these
Answer» D. All of above
50.

The operator used for dereferencing or indirection is ____

A. >>
B. &
C. *
D. ->
E. None of these
Answer» D. ->