What will be the output of the following C++ code?
#include <iostream>
#include <exception>
using namespace std;
class base { virtual void dummy() {} };
class derived: public base { int a; };
int main ()
{
try
{
base * pba = new derived;
base * pbb = new base;
derived * pd;
pd = dynamic_cast<derived*>(pba);
if (pd == 0)
cout << "Null pointer on first type-cast" << endl;
pd = dynamic_cast<derived*>(pbb);
if (pd == 0)
cout << "Null pointer on second type-cast" << endl;
}
catch (exception& e)
{
cout << "Exception: " << e.what();
}
return 0;
}A. Null pointer on first type-cast
B. Null pointer on second type-cast
C. Exception
D. Null pointer on third type-cast
Select an option to see the answer and solution.
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
struct A
{
virtual ~A()
{
cout << "~A()" << endl;
}
void operator delete[](void* p, size_t)
{
cout << "A :: operator delete[]" << endl;
delete [] p;
}
};
struct B : A
{
void operator delete[](void* p, size_t)
{
cout << "B :: operator delete[]" << endl;
delete [] p;
}
};
int main()
{
A* bp = new B[3];
delete[] bp;
};A. ~A()
B. A :: operator delete[]
C. B :: operator delete[]
D. Warning
Select an option to see the answer and solution.
What is the Run-Time Type Information?
A. Information about an object's data type at runtime
B. Information about the variables
C. Information about the given block
D. Information about the functions
Select an option to see the answer and solution.
What will be the output of the following C++ code?
#include <iostream>
#include <exception>
#include <cstdlib>
using namespace std;
void myterminate ()
{
cerr << "terminate handler called";
abort();
}
int main (void)
{
set_terminate (myterminate);
throw 0;
return 0;
}A. terminate handler called
B. aborted
C. both terminate handler & Aborted
D. runtime error
Select an option to see the answer and solution.
Which function is used to check whether a character is tab or a control code?
A. isspace()
B. isalnum()
C. iscntrl()
D. isblank()
Select an option to see the answer and solution.
What will be the output of the following C++ code?
#include
int main ()
{
FILE * p;
long size;
p = fopen ("test.txt", "rb");
if (p == NULL)
perror ("Error opening file");
else
{
fseek (p, 0, SEEK_END);
size = ftell (p);
fclose (p);
printf (" %ld\n", size);
}
return 0;
} A. 10
B. 20
C. 5
D. Depends upon the file
Select an option to see the answer and solution.
What does the first parameter of the main function represent?
A. Number of command line arguments
B. List of command line arguments
C. Dictionary of command line arguments
D. Stack of command line arguments
Select an option to see the answer and solution.
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);
vector<int> :: iterator i;
i = v.begin();
*i = 3;
for (i = v.begin(); i != v.end(); ++i)
cout << *i << " ";
cout<<endl;
return 0;
}A. 1 2 3 4 5
B. 3 2 3 4 5
C. 5 4 3 2 1
D. 3 3 3 3 3
Select an option to see the answer and solution.
Which looping process is best used when the number of iterations is known?
A. for
B. while
C. do-while
D. all looping processes require that the iterations be known
Select an option to see the answer and solution.
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class MyException
{
public:
MyException(int value) : mValue(value)
{
}
int mValue;
};
class MyDerivedException : public MyException
{
public:
MyDerivedException(int value, int anotherValue) : MyException(value), mAnotherValue(anotherValue)
{
}
int mValue;
int mAnotherValue;
};
void doSomething()
{
throw MyDerivedException(10,20);
}
int main()
{
try
{
doSomething();
}
catch (MyDerivedException &exception)
{
cout << "\nCaught Derived Class Exception\n";
}
catch (MyException &exception)
{
cout << "\nCaught Base Class Exception\n";
}
return 0;
}A. Caught Base Class Exception
B. Caught Derived Class Exception
C. Caught Base & Derived Class Exception
D. Caught Base Class
Select an option to see the answer and solution.
What is meant by ofstream in c++?
A. Writes to a file
B. Reads from a file
C. Writes to a file & Reads from a file
D. delete a file
Select an option to see the answer and solution.
What is the use of reference member type in allocator?
A. Point to an element
B. Quantities of element
C. Reference to an element
D. Sequence of an element
Select an option to see the answer and solution.
Pick out the correct answer.
A. Exceptions are not suitable for critical points in code
B. Exception are suitable for critical points in code
C. Exceptions are used when postconditions of a function cannot be satisfied
D. Throw block should be placed after try block
Select an option to see the answer and solution.
What are different operations are used in Pseudo-random number engines?
A. operator()
B. min()
C. max()
D. all of the mentioned
Select an option to see the answer and solution.
How many different ways are there to access an element of array classes at the ith position?
Select an option to see the answer and solution.
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,2,3,4,5};
for (int&c : fl1)
cout << c << " ";
cout<<endl;
forward_list<int>::iterator ptr = fl1.begin();
fl1.erase_after(ptr);
for (int&c : fl1)
cout << c << " ";
cout<<endl;
return 0;
}A. 1 2 3 4 5
1 2 3 4 5
B. 1 2 3 4 5
1 3 4 5
C. 1 2 3 4 5
2 3 4 5
D. 1 2 3 4 5
1
Select an option to see the answer and solution.
Which of the following is correct way of copying the values of pair p1 into other pair p2?
A. pair <type,type> p2 = p1;
B. pair <type,type> p2(p1);
C. Both pair <type,type> p2 = p1; and pair <type,type> p2(p1);
D. Pair <int,int> p2.copy(p1);
Select an option to see the answer and solution.
What will be the output of the following C++ code?
#include <iostream>
#include <vector>
#include<iterator>
using namespace std;
int main ()
{
vector<int> myvector;
for (int i = 1; i <= 10; i++)
myvector.push_back(i);
myvector.erase (myvector.begin() + 6);
myvector.erase (myvector.begin(), myvector.begin() + 4);
for (unsigned i = 0; i < myvector.size(); ++i)
cout << ' ' << myvector[i];
return 0;
}A. 5 6 7 8 9
B. 5 6 8 9 10
C. 6 7 8 9 10
D. 4 7 5 9 10
Select an option to see the answer and solution.
Which is the correct syntax of constructing a bitset?
A. bitset<size> b;
B. bitset<size> b(12);
C. bitset<size> b(string("1100"));
D. all of the mentioned
Select an option to see the answer and solution.
In what form does the STL provides heap?
A. queue
B. list
C. vector
D. priority_queue
Select an option to see the answer and solution.