1. What does a default header file contain?
2. What will be the capacity of vector at the end 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);
v.reserve(50);
cout<<v.capacity();
return 0;
}
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> v;
for (int i = 1; i <= 5; i++)
v.push_back(i);
v.reserve(50);
cout<<v.capacity();
return 0;
}3. What will be the output of the following C++ code?
#include <iostream>
#include <deque>
using namespace std;
int main ()
{
unsigned int i;
deque<int> a (3,100);
deque<int> b (5,200);
a.swap(b);
cout << "a contains:";
for (deque<int>::iterator it = a.begin(); it != a.end(); ++it)
cout << ' ' << *it;
cout << "b contains:";
for (deque<int>::iterator it = b.begin(); it != b.end(); ++it)
cout << ' ' << *it;
return 0;
}
#include <iostream>
#include <deque>
using namespace std;
int main ()
{
unsigned int i;
deque<int> a (3,100);
deque<int> b (5,200);
a.swap(b);
cout << "a contains:";
for (deque<int>::iterator it = a.begin(); it != a.end(); ++it)
cout << ' ' << *it;
cout << "b contains:";
for (deque<int>::iterator it = b.begin(); it != b.end(); ++it)
cout << ' ' << *it;
return 0;
}4. What will be the output of the following C++ code?
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
bitset<8> b1(string("15"));
cout<<b1;
}
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
bitset<8> b1(string("15"));
cout<<b1;
}5. Which member function is used to determine whether the stream object is currently associated with a file?
6. In how many ways we can handle errors in any class?
7. How to handle the exception in constructor?
8. What is the syntax of declaraing a forward_list?
9. What will be the output of the following C++ code?
#include <iostream>
#include <typeinfo>
using namespace std;
class Polymorphic {virtual void Member(){}};
int main ()
{
try
{
Polymorphic * pb = 0;
typeid(*pb);
}
catch (exception& e)
{
cerr << "exception caught: " << e.what() << endl;
}
return 0;
}
#include <iostream>
#include <typeinfo>
using namespace std;
class Polymorphic {virtual void Member(){}};
int main ()
{
try
{
Polymorphic * pb = 0;
typeid(*pb);
}
catch (exception& e)
{
cerr << "exception caught: " << e.what() << endl;
}
return 0;
}10. 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<<b1<<endl<<b2;
}
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
bitset<8> b1(95);
bitset<8> b2 = b1 >> 3;
cout<<b1<<endl<<b2;
}Read More Section(C plus plus miscellaneous)
Each Section contains maximum 100 MCQs question on C plus plus miscellaneous. To get more questions visit other sections.
- C plus plus miscellaneous - Section 1
- C plus plus miscellaneous - Section 2
- C plus plus miscellaneous - Section 3
- C plus plus miscellaneous - Section 4
- C plus plus miscellaneous - Section 5
- C plus plus miscellaneous - Section 6
- C plus plus miscellaneous - Section 7
- C plus plus miscellaneous - Section 8
- C plus plus miscellaneous - Section 9
- C plus plus miscellaneous - Section 11
