Explore topic-wise MCQs in C++ Programming.

This section includes 26 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 
#include
using namespace std;
void function(std::string message, ...);
int main()
{
function("InterviewMania", 5, 7, 10, 8, 9);
return 0;
}
void function(std::string message, ...)
{
va_list ptr;
int number;
va_start(ptr, message);
number = va_arg(ptr, int);
number = va_arg(ptr, int);
cout << number;
}

A. InterviewMania
B. 5
C. 7
D. 8
E. Compilation Error
Answer» D. 8
2.

What is the output of this program?
#include 
#include
using namespace std;
int funcion(char ch,...);
int main()
{
int p, q;
p = funcion('B', 2, 3, 4);
q = funcion('3', 2.0, 2, '3', 2.0f, 10);
cout << p< return 0;
}
int funcion(char ch,...)
{
return ch;
}

A. 51 66
B. 66 51
C. Compilation Error
D. Runtime Error
E. None of these
Answer» C. Compilation Error
3.

What is the output of this program?
#include 
using namespace std;
int add(int p, int q);
int main()
{
int n = 15, m = 16;
cout << add(n, m) << endl;
return 0;
}
int add(int p, int q )
{
int sum = p + q;
p = 20;
return p + q;
}

A. 36
B. 15
C. 16
D. 20
E. None of these
Answer» E. None of these
4.

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

A. 11
B. 123
C. 321
D. 132
E. None of these
Answer» E. None of these
5.

What is the new value of P?
#include 
using namespace std;
void function(int &p)
{
p = 15;
}
int main()
{
int p = 12;
function(p);
cout << "New value of P is " << p;
return 0;
}

A. New value of P is 12
B. Compilation Error
C. New value of P is 15
D. Runtime Error
E. None of these
Answer» D. Runtime Error
6.

What is the output of this program?
#include 
using namespace std;
int function(int p = 12, int q)
{
int s;
s = p + q;
return s;
}
int main()
{
cout << function(15);
return 0;
}

A. 15
B. 12
C. Runtime Error
D. Compilation Error
E. None of these
Answer» E. None of these
7.

What is the output of this program?
#include 
using namespace std;
void copy (int& p, int& q, int& r)
{
p = p * 1;
q = q * 2;
r = r * 3;
}
int main ()
{
int m = 6, n = 3, o = 2;
copy (m, n, o);
cout << "M = " << m << ", N = " << n << ", O = " << o;
return 0;
}

A. M = 6, N = 6, O = 6
B. N = 6, O = 6, M = 6
C. O = 6, M = 6
D. Compilation Error
E. None of these
Answer» B. N = 6, O = 6, M = 6
8.

What is the output of this program?
#include 
#include
using namespace std;
int Addition(int number, ...)
{
int sum = 0;
va_list args;
va_start (args,number);
for (int i = 0; i < number; i++)
{
int number = va_arg (args,int);
sum += number;
}
va_end (args);
return sum;
}
int main (void)
{
int Result = Addition(1, 10, 9, -1, 13, 23, -2, 9, 17);
cout << "The result is " << Result;
return 0;
}

A. 1
B. 5
C. 10
D. 20
E. Compilation Error
Answer» D. 20
9.

What is the output of this program?
#include 
#include
using namespace std;
float avg( int Count, ... )
{
va_list num;
va_start(num, Count);
int Sum = 0;
for (int i = 0; i < Count; ++i )
Sum += va_arg(num, int);
va_end(num);
return (Sum/Count);
}
int main()
{
float AVG = avg(5, 0, 1, 2, 3, 4);
cout << "Average of first 5 whole numbers : " << AVG;
return 0;
}

A. 2
B. 3
C. 4
D. 5
E. Compilation Error
Answer» B. 3
10.

What is the output of this program?
#include 
#include
using namespace std;
string askMessage(string Message = "Please enter a message: ");
int main()
{
string Input = askMessage();
cout << "Here is your message: " << Input;
return 0;
}
string askMessage(string Message)
{
string Input;
cout << Message;
cin >> Input;
return Input;
}

A. Compilation Error
B. Runtime Error
C. Garbage value
D. The message you entered
E. None of these
Answer» E. None of these
11.

What is the output of this program?
#include 
using namespace std;
void function(int p, bool condition = true)
{
if (condition == true )
{
cout << "Condition is true. P = " << p;
}
else
{
cout << "Condition is false. P = " << p;
}
}
int main()
{
function(250, false);
return 0;
}

A. Condition is true. P = 250
B. 200
C. Condition is false. P = 250
D. True
E. False
Answer» D. True
12.

What is the output of this program?
#include 
#include
using namespace std;
void List(int, ...);
int main()
{
List(2, 5, 10);
List(3, 6, 9, 7);
return 0;
}
void List(int num, ...)
{
va_list a;
int k;
va_start(a, num);
while (num-->0)
{
k = va_arg(a, int);
cout << k;
}
va_end(a);
}

A. 2 5 10 3 6 9 7
B. 2 3 5 6 7 9 10
C. 10 9 7 6 5 3 2
D. 5 6 7 9 3 2 10
E. 5 10 6 9 7
Answer» F.
13.

What will happen when we use void in argument passing?

A. Maybe or may not be return any value to its caller
B. It will not return value to its caller
C. It will return value to its caller
D. All of above
E. None of these
Answer» C. It will return value to its caller
14.

What is the new value of P?

A. New value of P is 12
B. Compilation Error
C. New value of P is 15
D. Runtime Error
E. None of these
Answer» D. Runtime Error
15.

What is the default return type of a function?

A. char
B. float
C. void
D. int
E. None of these
Answer» D. int
16.

If we start our function call with default arguments means, what will be proceeding arguments?

A. default arguments
B. user argument
C. empty arguments
D. All of above
E. None of these
Answer» B. user argument
17.

What is the maximum number of arguments or parameters that can be present in one function call?

A. 16
B. 255
C. 64
D. 256
E. None of these
Answer» E. None of these
18.

How can you access the arguments that are manipulated in the function?

A. arg_list
B. va_list
C. both arg_list & va_list
D. All of above
E. None of these
Answer» C. both arg_list & va_list
19.

Which value will it take when both user and default values are given?

A. custom value
B. default value
C. user value
D. All of above
E. None of these
Answer» D. All of above
20.

What we can t place followed by the non-default arguments?

A. default arguments
B. trailing arguments
C. both default & trailing arguments
D. All of above
E. None of these
Answer» B. trailing arguments
21.

Which header file is used to pass unknown number of arguments to function?

A. stdarg.h
B. stdlib.h
C. string.h
D. All of above
E. None of these
Answer» B. stdlib.h
22.

Where can the default parameter be placed by the user?

A. rightmost
B. leftmost
C. both rightmost & leftmost
D. All of above
E. None of these
Answer» B. leftmost
23.

If the user did not supply the value, what value will it take?

A. rise an error
B. default value
C. both rise an error & default value
D. All of above
E. None of these
Answer» C. both rise an error & default value
24.

How many ways of passing a parameter are there in c++?

A. 4
B. 3
C. 2
D. 1
E. None of these
Answer» C. 2
25.

What will initialize the list of arguments in stdarg.h header file?

A. va_start
B. va_arg
C. va_list
D. All of above
E. None of these
Answer» B. va_arg
26.

Which header file should you include if you are to develop a function that can accept variable number of arguments?

A. stdio.h
B. varag.h
C. stdarg.h
D. stdlib.h
E. None of these
Answer» D. stdlib.h