1. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
double division(int a, int b)
{
if (b == 0)
{
throw "Division by zero condition!";
}
return (a / b);
}
int main ()
{
int x = 50;
int y = 0;
double z = 0;
try
{
z = division(x, y);
cout << z << endl;
}
catch (const msg)
{
cerr << msg << endl;
}
return 0;
}
#include <iostream>
using namespace std;
double division(int a, int b)
{
if (b == 0)
{
throw "Division by zero condition!";
}
return (a / b);
}
int main ()
{
int x = 50;
int y = 0;
double z = 0;
try
{
z = division(x, y);
cout << z << endl;
}
catch (const msg)
{
cerr << msg << endl;
}
return 0;
}2. Which of the following is correct syntax of making heap from a vector v?
3. What is mandatory for designing a new container?
4. Pick out the incorrect method in non-modifying sequence algorithm?
5. What do container adapter provide to interface?
6. Given the below class, what is the correct syntax of declaring a functor that adds 10 to each of the passed argument?
class Add
{
int x;
public:
Add(int x){
this->x = x;
}
int operator()(int a){
return x+a;
}
};
class Add
{
int x;
public:
Add(int x){
this->x = x;
}
int operator()(int a){
return x+a;
}
};7. setprecision requires which of the following header file?
8. What is the correct syntax of constructing any using assignment operator?
9. What is random_device?
10. What will be the output of the following C++ code?
#include <stdexcept>
#include <limits>
#include <iostream>
using namespace std;
void func(int c)
{
if (c < numeric_limits<char> :: max())
throw invalid_argument("MyFunc argument too large.");
else
{
cout<<"Executed";
}
}
int main()
{
try
{
func(256);
}
catch(invalid_argument& e)
{
cerr << e.what() << endl;
return -1;
}
return 0;
}
#include <stdexcept>
#include <limits>
#include <iostream>
using namespace std;
void func(int c)
{
if (c < numeric_limits<char> :: max())
throw invalid_argument("MyFunc argument too large.");
else
{
cout<<"Executed";
}
}
int main()
{
try
{
func(256);
}
catch(invalid_argument& e)
{
cerr << e.what() << endl;
return -1;
}
return 0;
}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 7
- C plus plus miscellaneous - Section 8
- C plus plus miscellaneous - Section 9
- C plus plus miscellaneous - Section 10
- C plus plus miscellaneous - Section 11
