C Plus Plus Miscellaneous — Part 1 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on C Plus Plus Miscellaneous — Part 1 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
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> #include <complex> using namespace std; int main() { complex <double> cn(3.0, 5.0); cout<<"Complex number is: "<<real(cn)<<" + "<<imag(cn)<<"i"<<endl; return 0; }
Correct Answer: Option A — Complex number is: 3 + 5i
Detailed Academic Explanation:
In the given C++ code, the complex class from the C++ Standard Library is used to represent a complex number. In the statement complex cn(3.0, 5.0) , the constructor initializes the real part as 3.0 and the imaginary part as 5.0 . The function real(cn) returns the real part of the complex number, which is 3 . The function imag(cn) returns the imaginary part, which is 5 . Hence, the output will be: Complex number is: 3 + 5i .
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> #include <vector> #include <algorithm> using namespace std; void Display(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); sort(vi.begin(), vi.end()); Display(vi); while(next_permutation(vi.begin(), vi.end())) Display(vi); return 0; }
Correct Answer: Option C — 5 3 3 5
Detailed Academic Explanation:
The C++ code uses the STL functions sort() and next_permutation() to display permutations of a vector. Initially, the vector vi contains two elements: 3 and 5 . The sort(vi.begin(), vi.end()) function arranges the elements in ascending order, so the first output will be 3 5 . Then, the next_permutation() function rearranges the vector to the next lexicographical permutation, which will be 5 3 , and it is displayed after sorting. After this, there are no more permutations, so the loop terminates. Thus, the output will be: 5 3 3 5.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the difference between '++i' and 'i++' in C++?
Correct Answer: Option C — '++i' increments the value of 'i' before returning it, while 'i++' increments the value of 'i' after returning it
Detailed Academic Explanation:
'++i' increments the value of 'i' before returning it, while 'i++' increments the value of 'i' after returning it is the correct answer to “What is the difference between '++i' and 'i++' in C++”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the 'const' qualifier indicate in C++?
Correct Answer: Option D — That the value of the variable cannot be changed
Detailed Academic Explanation:
That the value of the variable cannot be changed is the correct answer to “What does the 'const' qualifier indicate in C++”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the 'inline' keyword in C++?
Correct Answer: Option C — To suggest the compiler to inline the function call
Detailed Academic Explanation:
To suggest the compiler to inline the function call is the correct answer to “What is the purpose of the 'inline' keyword in C++”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the 'volatile' qualifier in C++?
Correct Answer: Option B — To indicate that a variable may be modified by external factors
Detailed Academic Explanation:
To indicate that a variable may be modified by external factors is the correct answer to “What is the purpose of the 'volatile' qualifier in C++”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is a valid way to initialize a constant variable in C++?
Correct Answer: Option C — Using the 'const' keyword
Detailed Academic Explanation:
Using the 'const' keyword is the correct answer to “Which of the following is a valid way to initialize a constant variable in C++”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the 'using' directive in C++?
Correct Answer: Option D — To introduce a name from a namespace into the current scope
Detailed Academic Explanation:
To introduce a name from a namespace into the current scope is the correct answer to “What is the purpose of the 'using' directive in C++”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is not a valid C++ data type?
Correct Answer: Option C — unsigned float
Detailed Academic Explanation:
unsigned float is the correct answer to “Which of the following is not a valid C++ data type”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the typeid operator in C++?
Correct Answer: Option A — To return the type of an expression
Detailed Academic Explanation:
To return the type of an expression is the correct answer to “What is the purpose of the typeid operator in C++”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the mutable keyword in C++ mean when applied to a class member function?
Correct Answer: Option D — It allows the member function to modify the object's data members declared as const
Detailed Academic Explanation:
It allows the member function to modify the object's data members declared as const is the correct answer to “What does the mutable keyword in C++ mean when applied to a class member function”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following correctly defines a lambda function in C++?
Correct Answer: Option C — auto lambda = [](int x, int y) { return x + y; }
Detailed Academic Explanation:
auto lambda = [](int x, int y) { return x + y; } is the correct answer to “Which of the following correctly defines a lambda function in C++”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the static_cast operator in C++?
Correct Answer: Option B — To perform explicit type conversions
Detailed Academic Explanation:
To perform explicit type conversions is the correct answer to “What is the purpose of the static_cast operator in C++”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is not a valid way to initialize an array in C++?
Correct Answer: Option D — int arr[5]; arr = {1, 2, 3, 4, 5}
Detailed Academic Explanation:
int arr[5]; arr = {1, 2, 3, 4, 5} is the correct answer to “Which of the following is not a valid way to initialize an array in C++”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the nullptr keyword represent in C++?
Correct Answer: Option A — A null pointer value
Detailed Academic Explanation:
A null pointer value is the correct answer to “What does the nullptr keyword represent in C++”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the std::move function in C++?
Correct Answer: Option D — To cast an object to an rvalue reference
Detailed Academic Explanation:
To cast an object to an rvalue reference is the correct answer to “What is the purpose of the std::move function in C++”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the std::initializer_list class in C++?
Correct Answer: Option C — To initialize containers with a list of values at compile time
Detailed Academic Explanation:
To initialize containers with a list of values at compile time is the correct answer to “What is the purpose of the std::initializer_list class in C++”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the volatile keyword in C++?
Correct Answer: Option B — To indicate that a variable may be changed unexpectedly by hardware or another thread
Detailed Academic Explanation:
To indicate that a variable may be changed unexpectedly by hardware or another thread is the correct answer to “What is the purpose of the volatile keyword in C++”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is not a valid C++ standard library container?
Correct Answer: Option C — ArrayList
Detailed Academic Explanation:
ArrayList is the correct answer to “Which of the following is not a valid C++ standard library container”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the const keyword in C++?
Correct Answer: Option D — To specify that a variable's value cannot be changed once initialized
Detailed Academic Explanation:
To specify that a variable's value cannot be changed once initialized is the correct answer to “What is the purpose of the const keyword in C++”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does RAII stand for in C++?
Correct Answer: Option A — Resource Acquisition Is Initialization
Detailed Academic Explanation:
Resource Acquisition Is Initialization is the correct answer to “What does RAII stand for in C++”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which class is used to design the base class?
Correct Answer: Option A — abstract class
Detailed Academic Explanation:
abstract class is the correct answer to “Which class is used to design the base class”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #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; }
Correct Answer: Option D — 0011
Detailed Academic Explanation:
0011 is the correct answer to “What will be the output of the following C++ code? #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; }”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Where does the abstract class is used?
Correct Answer: Option A — base class only
Detailed Academic Explanation:
base class only is the correct answer to “Where does the abstract class is used”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which is the best design choice for using pointer to member function?
Correct Answer: Option A — Interface
Detailed Academic Explanation:
Interface is the correct answer to “Which is the best design choice for using pointer to member function”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to check whether a character is punctuation mark?
Correct Answer: Option D — ispunct()
Detailed Academic Explanation:
ispunct() is the correct answer to “Which function is used to check whether a character is punctuation mark”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to calculate the norm of a complex number?
Correct Answer: Option B — norm()
Detailed Academic Explanation:
norm() is the correct answer to “Which function is used to calculate the norm of a complex number”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> #include <cctype> using namespace std; int main(int argc, char const *argv[]) { char arr[20] = "\'H3ll0\'"; for(int i=0;i<8;i++) { cout<<(bool)ispunct(arr[i]); } }
Correct Answer: Option A — 10000010
Detailed Academic Explanation:
10000010 is the correct answer to “What will be the output of the following C++ code? #include <iostream> #include <cctype> using namespace std; int main(int argc, char const *argv[]) { char arr[20] = "\'H3ll0\'"; for(int i=0;i<8;i++) { cout<<(bool)ispunct(arr[i]); } }”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the syntax of printing the first element of an array Arr using get() function?
Correct Answer: Option B — get<0>(Arr)
Detailed Academic Explanation:
get<0>(Arr) is the correct answer to “What is the syntax of printing the first element of an array Arr using get() function”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 30 of 40
★ FPSC
★ PPSC
★ 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,7,8,9,10}; forward_list<int> fl2 = {2,3,4,5,6}; fl1.splice_after(fl1.begin(), fl2); for (int&c : fl1) cout << c << " "; cout<<endl; return 0; }
Correct Answer: Option B — 1 2 3 4 5 6 7 8 9 10
Detailed Academic Explanation:
1 2 3 4 5 6 7 8 9 10 is the correct answer to “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,7,8,9,10}; forward_list<int> fl2 = {2,3,4,5,6}; fl1.splice_after(fl1.begin(), fl2); for (int&c : fl1) cout << c << " "; cout<<endl; return 0; }”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is correct about map and multimap?
Correct Answer: Option C — Multimap can have same keys whereas the map cannot
Detailed Academic Explanation:
Multimap can have same keys whereas the map cannot is the correct answer to “Which of the following is correct about map and multimap”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is correct about Input Iterators?
Correct Answer: Option D — All of the mentioned
Detailed Academic Explanation:
All of the mentioned is the correct answer to “Which of the following is correct about Input Iterators”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> #include <functional> #include <numeric> using namespace std; int myop (int x, int y) { return x + y; } int main () { int val[] = {1, 2, 3, 5}; int result[7]; adjacent_difference (val, val + 7, result); for (int i = 0; i < 4; i++) cout << result[i] <<' '; return 0; }
Correct Answer: Option A — 1 1 1 2
Detailed Academic Explanation:
1 1 1 2 is the correct answer to “What will be the output of the following C++ code? #include <iostream> #include <functional> #include <numeric> using namespace std; int myop (int x, int y) { return x + y; } int main () { int val[] = {1, 2, 3, 5}; int result[7]; adjacent_difference (val, val + 7, result); for (int i = 0; i < 4; i++) cout << result[i] <<' '; return 0; }”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Pick the incorrect statement.
Correct Answer: Option C — Insertion in vectors always takes constant time
Detailed Academic Explanation:
Insertion in vectors always takes constant time is the correct answer to “Pick the incorrect statement.”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Given below classes which of the following are the possible row entries in vtable of D1 class? class Base { public: virtual void function1() {}; virtual void function2() {}; }; class D1: public Base { public: virtual void function1() {}; }; class D2: public Base { public: virtual void function2() {}; };
Correct Answer: Option B — D1::function1() and Base::function2()
Detailed Academic Explanation:
D1::function1() and Base::function2() is the correct answer to “Given below classes which of the following are the possible row entries in vtable of D1 class? class Base { public: virtual void function1() {}; virtual void function2() {}; }; class D1: public Base { public: virtual void function1() {}; }; class D2: public Base { public: virtual void function2() {}; };”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the capacity of the vector after 10 is pushed into the vector in the following C++ code? #include <iostream> #include <vector> using namespace std; int main() { vector<int> v; for (int i = 1; i <= 5; i++) v.push_back(i); cout<<v.capacity()<<endl; v.shrink_to_fit(); cout<<v.capacity()<<endl; v.push_back(10); return 0; }
Correct Answer: Option B — 10
Detailed Academic Explanation:
10 is the correct answer to “What will be the capacity of the vector after 10 is pushed into the vector in the following C++ code? #include <iostream> #include <vector> using namespace std; int main() { vector<int> v; for (int i = 1; i <= 5; i++) v.push_back(i); cout<<v.capacity()<<endl; v.shrink_to_fit(); cout<<v.capacity()<<endl; v.push_back(10); return 0; }”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which header file is used for generating random numbers?
Correct Answer: Option D — <random>
Detailed Academic Explanation:
<random> is the correct answer to “Which header file is used for generating random numbers”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include<iostream> using namespace std; class X { int m; public: X() : m(10) { } X(int mm): m(mm) { } int getm() { return m; } }; class Y : public X { int n; public: Y(int nn) : n(nn) {} int getn() { return n; } }; int main() { Y yobj( 100 ); cout << yobj.getm() << " " << yobj.getn() << endl; }
Correct Answer: Option A — 10 100
Detailed Academic Explanation:
10 100 is the correct answer to “What will be the output of the following C++ code? #include<iostream> using namespace std; class X { int m; public: X() : m(10) { } X(int mm): m(mm) { } int getm() { return m; } }; class Y : public X { int n; public: Y(int nn) : n(nn) {} int getn() { return n; } }; int main() { Y yobj( 100 ); cout << yobj.getm() << " " << yobj.getn() << endl; }”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 39 of 40
★ FPSC
★ PPSC
★ 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(45); cout<<~b1<<endl; cout<<(b1|b2)<<endl; cout<<(b1&b2)<<endl; }
Correct Answer: Option A — 10100000 01111111 00001101
Detailed Academic Explanation:
10100000 01111111 00001101 is the correct answer to “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(45); cout<<~b1<<endl; cout<<(b1|b2)<<endl; cout<<(b1&b2)<<endl; }”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to check whether a character is a number?
Correct Answer: Option C — isdigit()
Detailed Academic Explanation:
isdigit() is the correct answer to “Which function is used to check whether a character is a number”. This question is standard in competitive examination syllabi for C Plus Plus Miscellaneous.
💡Key Conceptual Anchor:C Plus Plus Miscellaneous
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡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.