Skip to main content

C Plus Plus Miscellaneous — Part 2 MCQs with Explanations

Practice high-yield Programming & Software Development MCQs on C Plus Plus Miscellaneous — Part 2 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.

Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40

Verified Practice Questions

Interactive test mode with detailed academic worked solutions

Live Progress | 0/40 answered
✓ 0 correct ✗ 0 wrong 0% score
Question 1 of 40
★ FPSC ★ PPSC

How many kinds of parameters are there in C++?

Question 2 of 40
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <functional> #include <numeric> using namespace std; int myfunction (int x, int y) { return x + 2 * y; } struct myclass { int operator()(int x, int y) { return x + 3 * y; } } myobject; int main () { int init = 100; int numbers[] = {10, 20, 30}; cout << accumulate(numbers, numbers + 3, init); cout << endl; }

Question 3 of 40
★ FPSC ★ PPSC

Which is used to get the input during runtime?

Question 4 of 40
★ FPSC ★ PPSC

What is meant by pure virtual function?

Question 5 of 40
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> using namespace std; class poly { protected: int width, height; public: void set_values(int a, int b) { width = a; height = b; } }; class Coutput { public: void output(int i); }; void Coutput::output(int i) { cout << i; } class rect:public poly, public Coutput { public: int area() { return(width * height); } }; class tri:public poly, public Coutput { public: int area() { return(width * height / 2); } }; int main() { rect rect; tri trgl; rect.set_values(3, 4); trgl.set_values(4, 5); rect.output(rect.area()); trgl.output(trgl.area()); return 0; }

Question 6 of 40
★ FPSC ★ PPSC

How many types of sequence operations are provided by the C++ algorithm STL?

Question 7 of 40
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <memory> #include <string> using namespace std; int main () { string numbers[] = {"steve", "jobs"}; pair <string*, ptrdiff_t> result = get_temporary_buffer<string>(2); if (result.second>0) { uninitialized_copy ( numbers, numbers + result.second, result.first ); for (int i = 0; i < result.second; i++) cout << result.first[i] << " "; return_temporary_buffer(result.first); } return 0; }

Question 8 of 40
★ FPSC ★ PPSC

What kind of iteration does forward_list provide in C++?

Question 9 of 40
★ FPSC ★ PPSC

Which of the following header file is needed to use vectors in your program?

Question 10 of 40
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <string> #include <iostream> using namespace std; void string_permutation( string& orig, string& perm ) { if (orig.empty()) { cout<<perm<<endl; return; } for (int i = 0; i < orig.size(); ++i) { string orig2 = orig; orig2.erase(i, 1); string perm2 = perm; perm2 += orig.at(i); string_permutation(orig2, perm2); } } int main() { string orig = "ter"; string perm; string_permutation(orig, perm); return 0; }

Question 11 of 40
★ FPSC ★ PPSC

What type of class template is list?

Question 12 of 40
★ FPSC ★ PPSC

Pick out the correct statement about vector.

Question 13 of 40
★ FPSC ★ PPSC

How do define the user-defined exceptions?

Question 14 of 40
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <vector> using namespace std; int main () { vector<int> first; first.assign (7,100); vector<int>::iterator it; it=first.begin()+1; int myints[] = {1776,7,4}; cout << int (first.size()) << '\n'; return 0; }

Question 15 of 40
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <Valarray> using namespace std; int main() { Valarray<int> varr = { 1, 2, 3, 4, 5 }; for (int &x: varr) cout << x << " "; cout<<endl; varr = varr.shift(2); for (int &x: varr) cout << x << " "; return 0; }

Question 16 of 40
★ FPSC ★ PPSC

What function will be called when we have an uncaught exception?

Question 17 of 40
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <vector> #include <forward_list> using namespace std; int main() { forward_list<int> fl1 = {1,2,3,4,5}; for (int&c : fl1) cout << c << " "; cout<<endl; fl1.remove_if([](int x){ return x > 3;}); for (int&c : fl1) cout << c << " "; cout<<endl; return 0; }

Question 18 of 40
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <valarray> using namespace std; int main() { valarray<int> varr = { 10, 2, 20, 1, 30 }; cout<<"Sum of array: "<<varr.sum(); return 0; }

Question 19 of 40
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> using namespace std; class Base { public: Base ( ) { cout << "1" << endl; } ~Base ( ) { cout << "2" << endl; } }; class Derived : public Base { public: Derived ( ) { cout << "3" << endl; } ~Derived ( ) { cout << "4" << endl; } }; int main( ) { Derived x; }

Question 20 of 40
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <bitset> using namespace std; int main() { bitset<8> b1(95); bitset<8> b2 = b1 << 3; cout<<b2; }

Question 21 of 40
★ FPSC ★ PPSC

What is the main feature of locale in C++?

Question 22 of 40
★ FPSC ★ PPSC

Elements in STL heap are removed in . . . . . . . .

Question 23 of 40
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <algorithm> #include <vector> using namespace std; int main () { vector<int> myvector; for (int i = 1; i < 5; ++i) myvector.push_back(i); rotate(myvector.begin(), myvector.begin() + 3, myvector.end( )); for (vector<int> :: iterator it = myvector.begin(); it != myvector.end(); ++it) cout << ' ' << *it; return 0; }

Question 24 of 40
★ FPSC ★ PPSC

What are command line arguments?

Question 25 of 40
★ FPSC ★ PPSC

How many parameters are there in getline function?

Question 26 of 40
★ FPSC ★ PPSC

Which of the following relationships is uni-directional?

Question 27 of 40
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int a = 10; if (a < 15) { time: cout << a; goto time; } break; return 0; }

Question 28 of 40
★ FPSC ★ PPSC

Which is used to create a pure virtual function?

Question 29 of 40
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; int main () { int num = 3; string str_bad = "wrong number used"; try { if ( num == 1 ) { throw 5; } if ( num == 2 ) { throw 1.1f; } if ( num != 1 || num != 2 ) { throw str_bad; } } catch (int a) { cout << "Exception is: " << a << endl; } catch (float b) { cout << "Exception is: " << b << endl; } catch (...) { cout << str_bad << endl; } return 0; }

Question 30 of 40
★ FPSC ★ PPSC

Which of the following function is used to insert an element at the end of a vector?

Question 31 of 40
★ FPSC ★ PPSC

What are the tuples in C++?

Question 32 of 40
★ FPSC ★ PPSC

How many ways of reusing are there in the class hierarchy?

Question 33 of 40
★ FPSC ★ PPSC

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

Question 34 of 40
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <string> #include <tuple> using namespace std; int main() { tuple <int, char, string> tp1; tuple <int, char, string> tp2; tp1 = make_tuple(6, 'a', "Hello"); tp2 = make_tuple(9, 'z', "World"); cout<<"("<<get<0>(tp1)<<", "<<get<1>(tp1)<<", "<<get<2>(tp1)<<")"<<endl; cout<<"("<<get<0>(tp2)<<", "<<get<1>(tp2)<<", "<<get<2>(tp2)<<")"<<endl; tp1.swap(tp2); cout<<"("<<get<0>(tp1)<<", "<<get<1>(tp1)<<", "<<get<2>(tp1)<<")"<<endl; cout<<"("<<get<0>(tp2)<<", "<<get<1>(tp2)<<", "<<get<2>(tp2)<<")"<<endl; return 0; }

Question 35 of 40
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <vector> #include <algorithm> using namespace std; void show(const vector<int>& vi) { for (size_t i = 0; i < vi.size(); ++i) cout << vi[i]; cout << endl; } int main() { vector<int> vi; vi.push_back(3); vi.push_back(5); vi.push_back(5); sort(vi.begin(), vi.end()); show(vi); while(next_permutation(vi.begin(), vi.end())) show(vi); return 0; }

Question 36 of 40
★ FPSC ★ PPSC

In how many different ways any-container can be constructed?

Question 37 of 40
★ FPSC ★ PPSC

What does this template function indicates? ================== template<class T, class U> U func(T a, U b) { cout<<a<<"\t"<<b; } ==================

Question 38 of 40
★ FPSC ★ PPSC

What will be the output of the following C++ code? #include <iostream> #include <algorithm> #include <vector> using namespace std; int main () { vector<int> v = {4,2,10,5,1,8}; sort(v.begin(), v.end()); if (binary_search(v.begin(), v.end(), 4)) cout << "found.\n"; else cout << "not found.\n"; return 0; }

Question 39 of 40
★ FPSC ★ PPSC

Identify the correct statement about throw(type).

Question 40 of 40
★ FPSC ★ PPSC

Which operator is used as catch-all handler?

✓ Link copied to clipboard
Continue Your Practice

Advance Html — Part 1

Master the next curriculum module with 40 exam-standard MCQs.

Next Practice Set →

💡 Examiner's Advisory for Programming & Software Development

In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.

More Modules in Programming & Software Development

View All →
📚

Study Guides

Topic summaries and syllabus breakdown

Explore Guides →
🎯

Complete Library

Search through 78,000+ verified MCQs

Browse Library →
📱

Mobile App

Offline mock tests and instant bookmarks

Get Mobile App →