C Plus Plus Miscellaneous - Study Mode
[#746] What will be the output of the following C++ code? #include <typeinfo>
#include <iostream>
using namespace std
class A
{
public:
virtual ~A()
}
int main()
{
A* a = NULL
try
{
cout << typeid(*a).name() << endl
}
catch (bad_typeid)
{
cout << "Object is NULL" << endl
}
}
Correct Answer
(D) object is NULL
[#747] What will be the output of the following C++ code? #include <iostream>
using namespace std
class student
{
public:
int rno , m1 , m2
protected:
void get()
{
rno = 15, m1 = 10, m2 = 10
}
}
class sports
{
public:
int sm
void getsm()
{
sm = 10
}
}
class statement : public student, public sports
{
int tot, avg
public:
void display()
{
tot = (m1 + m2 + sm)
avg = tot / 3
cout << tot
cout << avg
}
void setObject()
{
get()
}
}
int main()
{
statement obj
obj.setObject()
obj.getsm()
obj.display()
}
Correct Answer
(A) 3010
[#748] What will be the output of 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.resize(4)
for (auto it = v.begin()
it != v.end()
it++)
cout << *it << " "
return 0
}
Correct Answer
(B) 1 2 3 4
[#749] What will be the output of the following C++ code? #include <iostream>
#include <utility>
#include <string>
using namespace std
int main ()
{
pair <int,int> p1(1,2)
pair <int,int> p2(3,4)
if(p1 <= p2)
cout<<"P1 is small"
else
cout<<"P2 is small"
return 0
}
Correct Answer
(A) P1 is small
[#750] What will be the output of the following C++ code? #include <iostream>
using namespace std
class sample
{
public:
virtual void example() = 0
}
class Ex1:public sample
{
public:
void example()
{
cout << "ubuntu"
}
}
class Ex2:public sample
{
public:
void example()
{
cout << " is awesome"
}
}
int main()
{
sample* arra[2]
Ex1 e1
Ex2 e2
arra[0]=&e1
arra[1]=&e2
arra[0]->example()
arra[1]->example()
}
Correct Answer
(C) ubuntu is awesome