Explore topic-wise MCQs in C++ Programming.

This section includes 19 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;
num = 45;
cout << hex << num << endl;
return 0;
}

A. 45
B. 2d
C. Compilation Error
D. Runtime Error
E. None of these
Answer» C. Compilation Error
2.

What is the output of this program?
#include <iostream>
using namespace std;
int main ()
{
char str[] = "Bjarne Stroustrup";
int val = 66;
char ch = 'B';
cout.width (5);
cout << right;
cout << val << endl;
return 0;
}

A. 66
B. B
C. Bjarne Stroustrup
D. Compilation Error
E. None of these
Answer» B. B
3.

What is the output of this program?
#include <iostream>
#include >locale<
using namespace std;
int main()
{
locale NewLocale("");
cout.imbue( NewLocale );
cout << (double) 6.1250024 << endl;
return 0;
}

A. 6.1250024
B. 6.125
C. Compilation Error
D. Runtime Error
E. None of these
Answer» C. Compilation Error
4.

What is the output of this program?
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main ()
{
string str;
float p = 0;
int q = 0;
cout << "Enter item price: ";
getline (cin, str);
stringstream(str) >> p;
cout << "Enter item quantity: ";
getline (cin, str);
stringstream(str) >> q;
cout << "Total item price: " << p * q << endl;
return 0;
}

A. 100
B. Compilation Error
C. Depends on entered value
D. Runtime Error
E. Garbage value
Answer» D. Runtime Error
5.

What is the output of this program?
#include <iostream>
using namespace std;
int main ()
{
int num;
cout << "Please enter a Number: ";
cin >> num + 10;
return 0;
}

A. Please enter a Number
B. 10
C. 15
D. Compilation Error
E. Runtime Error
Answer» E. Runtime Error
6.

What is the output of this program?
#include <iostream>
using namespace std;
int main ()
{
int num;
num = -25;
cout.width(4);
cout << internal << num << endl;
return 0;
}

A. 25
B. -25
C. - 25
D. Compilation Error
E. None of these
Answer» D. Compilation Error
7.

What is the output of this program in the Example.txt file?
#include <fstream>
using namespace std;
int main ()
{
long pos;
ofstream outfile;
outfile.open ("Example.txt");
outfile.write ("This is a Sample",16);
pos = outfile.tellp();
outfile.seekp (pos - 7);
outfile.write (" Ex", 6);
outfile.close();
return 0;
}

A. This is a Sample
B. Ex
C. Example.txt
D. This is a Example
E. None of these
Answer» E. None of these
8.

What is the output of this program?
#include <iostream>
using namespace std;
int main( )
{
char line[50];
cin.getline( line, 50, 'p' );
cout << line;
return 0;
}

A. 50
B. p
C. Compilation Error
D. It will print what we enter till character p is encountered in the input data
E. None of these
Answer» E. None of these
9.

What is the output of this program?
#include <iostream>
#include <ios>
#include <istream>
#include <limits>
using namespace std;
template <typename CharT>
void ignore_line ( basic_istream& in )
{
in.ignore ( numeric_limits :: max(), in.widen ( ' n' ) );
}
int main()
{
cout << "First Any Number or String: ";
cin.get();
cout << "Clearing cin Data. n";
cin.clear();
ignore_line ( cin );
cout << "All done Smoothly. n";
}

A. First Any Number or String:
B. Clearing cin Data.
C. Compilation Error
D. Runtime Error
E. None of these
Answer» F.
10.

When will the cin can start processing of input?

A. After pressing any key
B. After pressing return key
C. BY pressing blank space
D. After pressing return key & BY pressing blank space
E. None of these
Answer» C. BY pressing blank space
11.

How many groups of output of operation are there in c++?

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

Which is used to get the input during runtime?

A. coi
B. cout
C. cin
D. All of above
E. None of these
Answer» D. All of above
13.

Where does a cin stops it extraction of data?

A. By seeing (
B. By seeing a blank space & (
C. By seeing a blank space
D. All of above
E. None of these
Answer» C. By seeing a blank space
14.

Which operator is used for input stream?

A. <
B. >
C. <<
D. >>
E. None of these
Answer» C. <<
15.

What must be specified when we construct an object of class ostream?

A. memory
B. stream
C. streambuf
D. All of above
E. None of these
Answer» D. All of above
16.

How many types of output stream classes are there in c++?

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

What is the output of this program in the Example.txt file?

A. This is a Sample
B. Ex
C. Example.txt
D. This is a Example
E. None of these
Answer» E. None of these
18.

What can be used to input a string with blank space?

A. putline
B. inline
C. getline
D. All of above
E. None of these
Answer» D. All of above
19.

How many parameters are there in getline function?

A. 1
B. 2
C. 3
D. 4
E. 2 or 3
Answer» F.