Question 1 of 25
Hints left: 3
Q1
Which of the following is/are advantage(s) of Sequence Container arrays over C-like arrays?
Q2
What do vectors represent?
Q3
What is the use of is_heap_until() function?
Q4
What is the Run-Time Type Information?
Q5
What will be the output of the following C++ code? #include <iostream> #include <string> #include <tuple> using namespace std; int main() { tuple <int, char, string> tp = {"Hello", 1, 's'}; return 0; }
Q6
What will be the output of the following C++ code? #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); }
Q7
What is meant by ofstream in c++?
Q8
What does the first parameter of the main function represent?
Q9
Which header file is required for using bitset in your program?
Q10
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; }
Q11
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; }
Q12
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; }
Q13
Pick out the correct statement.
Q14
What type of comments does c++ support?
Q15
Which looping process is best used when the number of iterations is known?
Q16
What will be the output of the following C++ code? #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; }
Q17
Which function is used to check whether a character is tab or a control code?
Q18
What will be the output of the following C++ code? #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; }
Q19
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; }
Q20
Which type of relationship is modelled by Aggregation?
Q21
Which of the following is correct about bitset and vector of bools?
Q22
Which function is used to get the absolute of a complex number?
Q23
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; };
Q24
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; }
Q25
Which operator is used to produce a certain number in a specific range?