Q641
Open questionSelect an option to see the answer and solution.
Practice every MCQ with options. Use Show answers when you want the correct option and solution.
1,008
Questions
33/51
Page
Pick an option on a question to see the right answer and solution.
Q641
Open questionSelect an option to see the answer and solution.
Q642
Open question#include <cstdlib>
#include <iostream>
using namespace std;
class X
{
public:
void* operator new(size_t sz) throw (const char*)
{
void* p = malloc(sz);
if (p == 0)
throw "malloc() failed";
return p;
}
void operator delete(void* p)
{
cout << "X :: operator delete(void*)" << endl;
free(p);
}
};
class Y
{
int filler[100];
public:
void operator delete(void* p, size_t sz) throw (const char*)
{
cout << "Freeing " << sz << " bytes" << endl;
free(p);
};
};
int main()
{
X* ptr = new X;
delete ptr;
Y* yptr = new Y;
delete yptr;
}Select an option to see the answer and solution.
Q643
Open questionSelect an option to see the answer and solution.
Q644
Open questionSelect an option to see the answer and solution.
Q645
Open questionSelect an option to see the answer and solution.
Q646
Open question#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.size()<<endl;
v.resize(4);
cout<<v.size()<<endl;
return 0;
}Select an option to see the answer and solution.
Q647
Open questionSelect an option to see the answer and solution.
Q648
Open question#include <iostream>
#include <string>
#include <tuple>
using namespace std;
int main()
{
tuple <int, char, string> tp = {"Hello", 1, 's'};
return 0;
}Select an option to see the answer and solution.
Q649
Open questionSelect an option to see the answer and solution.
Q650
Open questionSelect an option to see the answer and solution.
Q651
Open questionSelect an option to see the answer and solution.
Q652
Open questionSelect an option to see the answer and solution.
Q653
Open question#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;
int op_increase (int i)
{
return ++i;
}
int main ()
{
vector<int> a;
vector<int> b;
for (int i = 1; i < 4; i++)
a.push_back (i * 10);
b.resize(a.size());
transform (a.begin(), a.end(), b.begin(), op_increase);
transform (a.begin(), a.end(), b.begin(), a.begin(), plus<int>());
for (vector<int> :: iterator it = a.begin(); it != a.end(); ++it)
cout << ' ' << *it;
return 0;
}Select an option to see the answer and solution.
Q654
Open questionSelect an option to see the answer and solution.
Q655
Open question#include <iostream>
using namespace std;
struct A
{
virtual void f()
{
cout << "Class A" << endl;
}
};
struct B : A
{
virtual void f()
{
cout << "Class B" << endl;
}
};
struct C : A
{
virtual void f()
{
cout << "Class C" << endl;
}
};
void f(A* arg)
{
B* bp = dynamic_cast<B*>(arg);
C* cp = dynamic_cast<C*>(arg);
if (bp)
bp -> f();
else if (cp)
cp -> f();
else
arg -> f();
};
int main()
{
A aobj;
C cobj;
A* ap = &cobj;
A* ap2 = &aobj;
f(ap);
f(ap2);
}Select an option to see the answer and solution.
Q656
Open questionSelect an option to see the answer and solution.
Q657
Open question#include <iostream>
using namespace std;
class Base
{
public:
int m;
Base(int n=0)
: m(n)
{
cout << "Base" << endl;
}
};
class Derived: public Base
{
public:
double d;
Derived(double de = 0.0)
: d(de)
{
cout << "Derived" << endl;
}
};
int main()
{
cout << "Instantiating Base" << endl;
Base cBase;
cout << "Instantiating Derived" << endl;
Derived cDerived;
return 0;
}Select an option to see the answer and solution.
Q658
Open questionSelect an option to see the answer and solution.
Q659
Open questionSelect an option to see the answer and solution.
Q660
Open questionSelect an option to see the answer and solution.