Explore topic-wise MCQs in C++ Programming.

This section includes 36 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>
#include <ctime>
#include &ltcstdlib>
using namespace std;
int main()
{
srand((unsigned)time(0));
int ran;
int L = 11, H = 100;
int R = (H - L) + 1;
for(int k = 0; k < 1; k++)
{
ran = L + int(R * rand() / (RAND_MAX + 1.0));
cout << ran << endl;
}
}

A. 100
B. 11
C. 1.0
D. Compilation Error
E. None of these
Answer» C. 1.0
2.

What is the output of this program?
 #include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
int main()
{
srand((unsigned)time(0));
int num;
for (int k = 0; k < 2; k++)
{
num = (rand() % 10) + 1;
cout << num;
}
}

A. 2
B. 20
C. 10
D. Any two number from 1 to 20
E. Compilation Error
Answer» E. Compilation Error
3.

What is the output of this program?
 #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main ()
{
srand (time(NULL));
printf ("Random number is: %d n", rand() % 50);
srand (1);
return 0;
}

A. 34
B. Compilation Error
C. 50
D. Any number from 0 to 49
E. None of these
Answer» B. Compilation Error
4.

What is the output of this program?
#include <iostream>
#include <complex>
using namespace std;
int main()
{
complex<double> Comp_double(4, 6);
complex<int> Comp_int(7, 8);
Comp_double *= 2;
Comp_double = Comp_int;
cout << Comp_double;
return 0;
}

A. (7,8)
B. (4,6)
C. (8,7)
D. (6,4)
E. None of these
Answer» B. (4,6)
5.

What is the output of this program?
#include <iostream>
#include <complex>
using namespace std;
int main()
{
complex<double> Comp1(3.0, 9.0), Comp2;
Comp2 = pow(Comp1, 2.0);
cout << Comp2;
return 0;
}

A. (3.0, 9.0)
B. (3.0, 2.0)
C. (9.0, 3.0)
D. (-72,54)
E. (-54,72)
Answer» E. (-54,72)
6.

What is the output of this program?
#include <iostream>
#include <complex>
using namespace std;
int main ()
{
complex<double> Comp (10.0, 4.0);
cout << imag(Comp) << endl;
return 0;
}

A. 10.0
B. 4.0
C. 4
D. 10
E. None of these
Answer» D. 10
7.

What is the output of this program?
#include <iostream>
#include <complex>
using namespace std;
int main()
{
complex<double> CompNum1(2.0, 4.0);
complex<float> CompNum2(polar(3.0, 0.25));
cout << (CompNum1 += sqrt(CompNum1)) << endl;
return 0;
}

A. (3.79891,5.11179)
B. (5.11179,3.79891)
C. 5.11179
D. 3.79891
E. None of these
Answer» B. (5.11179,3.79891)
8.

What is the output of this program?
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << numeric_limits<short int> :: max() << endl;
}

A. 767
B. 327
C. 32767
D. Compilation Error
E. None of these
Answer» D. Compilation Error
9.

What is the output of this program?
#include <iostream>
#include <limits>
using namespace std;
int main ()
{
cout << boolalpha;
cout << numeric_limits<int> :: has_infinity << ' n';
return 0;
}

A. true
B. false
C. Compilation Error
D. Runtime Error
E. None of these
Answer» C. Compilation Error
10.

What is the output of this program?
#include <iostream>
#include <functional>
#include <numeric>
using namespace std;
int Accumulator (int n, int m)
{
return n - m;
}
int Product (int n, int m)
{
return n + m;
}
int main ()
{
int p = 150;
int Array1[] = {12, 22, 33};
int Array2[] = {11, 12, 13};
cout << inner_product(Array1, Array1 + 3, Array2, p ,Accumulator,
Product);
cout << endl;
return 0;
}

A. 150
B. 12
C. 22
D. 33
E. 47
Answer» F.
11.

What is the output of this program?
#include <iostream>
#include <functional>
#include <numeric>
using namespace std;
int mnewfunction (int n, int m)
{
return n + 3 * m;
}
struct N
{
int operator()(int n, int m)
{
return n + 3 * m;
}
} structObject;
int main ()
{
int a = 200;
int Arr[] = {11, 21, 31};
cout << accumulate (Arr, Arr + 3, a, minus<int>() );
cout << endl;
return 0;
}

A. 21
B. 31
C. 200
D. 137
E. None of these
Answer» E. None of these
12.

What is the output of this program?
 #include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
cout << RAND_MAX << endl;
}

A. Depends on the compiler
B. Compilation Error
C. Runtime Error
D. Garbage value
E. None of these
Answer» B. Compilation Error
13.

What is the output of this program?
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int Ran = rand();
cout << Ran << endl;
}

A. 9383
B. 18042
C. 1804289383
D. 0 to RAND_MAX
E. None of these
Answer» E. None of these
14.

What is the output of this program?
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << numeric_limits<float> :: min_exponent << endl;
}

A. 125
B. 123
C. 124
D. -125
E. -100
Answer» E. -100
15.

What is the output of this program?
 #include <iostream> 
#include <limits>
using namespace std;
int main( )
{
cout << numeric_limits<float> :: digits10 << endl;
cout << numeric_limits<double> :: digits10 << endl;
float f = 99999999;
cout.precision ( 10 );
cout << f << endl;
}

A. 100000000
B. 15
C. 6
D. All of above
E. None of these
Answer» B. 15
16.

What is the output of this program?
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << numeric_limits<float> :: is_exact;
cout << numeric_limits<double> :: is_exact;
cout << numeric_limits<long int> :: is_exact;
cout << numeric_limits<unsigned char> :: is_exact;
}

A. 1100
B. 1001
C. 0011
D. Compilation Error
E. None of these
Answer» D. Compilation Error
17.

What is the output of this program?
 #include <iostream>
#include <functional>
#include <numeric>
using namespace std;
int myop (int p, int q)
{
return p + q + 1;
}
int main ()
{
int value[] = {11, 12, 13, 14, 15, 16};
int Res[5];
partial_sum (value, value + 5, Res);
for (int k = 0; k < 6; k++)
cout << Res[k] << ' ';
return 0;
}

A. 11 23 36
B. 50 65 0
C. 23 36 50
D. 11 23 36 50 65 0
E. None of these
Answer» E. None of these
18.

What is the output of this program?
#include <iostream>
#include <functional>
#include <numeric>
using namespace std;
int Function (int p, int q)
{
return p + 2 * q;
}
struct ClassN
{
int operator()(int p, int q)
{
return p + 3 * q;
}
} object;
int main ()
{
int num = 110;
int Array[] = {12, 25, 53};
cout << accumulate(Array, Array + 3, num);
cout << endl;
}

A. 110
B. 12
C. 25
D. 53
E. 200
Answer» F.
19.

What is the output of this program?
 #include <iostream>
#include <functional>
#include <numeric>
using namespace std;
int myop (int p, int q)
{
return p + q;
}
int main ()
{
int value[] = {11, 12, 13, 15, 17};
int Res[5];
adjacent_difference (value, value + 7, Res);
for (int k = 0; k < 5; k++)
cout << Res[k] < return 0;
}

A. 11 1 1 2 2
B. 11 1 1 2
C. 1 2 2
D. 1 2
E. 1
Answer» B. 11 1 1 2
20.

What is the output of this program?
#include <iostream>
#include <complex>
using namespace std;
int main()
{
complex<double> CompNum1(2.0,4.0);
cout << "Complex Number: " << CompNum1;
complex<float> CompNum2(polar(3.0,0.25));
cout << CompNum1 + complex<double>(CompNum2.real(),CompNum2.imag());
return 0;
}

A. Complex Number: (4.90674,4.74221)(2,4)
B. Compilation Error
C. Runtime Error
D. Complex Number: (2,4)(4.90674,4.74221)
E. None of these
Answer» E. None of these
21.

What is the output of this program?
#include <iostream>
#include <complex>
using namespace std;
int main()
{
complex<int> num(4, 5);
num = num * 7 / 4;
cout << num;
return 0;
}

A. (8,7)
B. (7,0)
C. (7,8)
D. (8,0)
E. None of these
Answer» D. (8,0)
22.

What is the default operation of adjacent_difference function in numeric library?

A. Multiplication
B. Addition
C. Difference
D. All of above
E. None of these
Answer» D. All of above
23.

How many parameters are available in srand function?

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

Which is a constant defined in header file?

A. Rand
B. Srand
C. RAND_MAX
D. All of above
E. None of these
Answer» D. All of above
25.

How many parameters are available in partial_sum function in c++?

A. 3 or 4
B. 2 or 3
C. 3
D. 2
E. None of these
Answer» B. 2 or 3
26.

Which header file is used to create the pseudo random generator?

A. cstdlib
B. random
C. both random and cstdlib
D. rand
E. None of these
Answer» D. rand
27.

Which operator is used to produce a certain number in a specific range?

A. %
B. modulo operator
C. both % and modulo operator
D. $
E. None of these
Answer» D. $
28.

Which can be used to create a random number without duplication?

A. number
B. Character
C. Time
D. Both Character & Time
E. None of these
Answer» D. Both Character & Time
29.

Which header file is used to declare the complex number?

A. complex number
B. complexnum
C. complex
D. All of above
E. None of these
Answer» D. All of above
30.

What will the max function in the numeric limit will return for type float?

A. Maximum finite value
B. Minimum finite value
C. Maximum finite value for a float type
D. All of above
E. None of these
Answer» D. All of above
31.

Where does the member should be defined if it is used in the program?

A. Scope
B. Namespace scope
C. Character scope
D. Namespace & Character scope
E. None of these
Answer» C. Character scope
32.

To which type does the numeric limits are suitable?

A. Arithmetic types
B. Character types
C. Mixed type
D. All of above
E. None of these
Answer» B. Character types
33.

Pick out the incorrect static function member in numeric limits.

A. max_finite
B. infinity
C. digits
D. denorm_min
E. None of these
Answer» B. infinity
34.

Which header file is used for the numeric limits in C++?

A. <limits>
B. <number>
C. <iostream>
D. All of above
E. None of these
Answer» B. <number>
35.

Which header file is used to operate on numeric sequences?

A. algorithm
B. number
C. numeric
D. All of above
E. None of these
Answer» D. All of above
36.

Which of the following is not a function of complex values?

A. cartesian
B. norm
C. imag
D. real
E. None of these
Answer» B. norm