Question 1 of 25
Hints left: 3
Q1
What will be the output of the following C++ code? #include <iostream> #include <vector> #include <algorithm> using namespace std; void Display(const vector<int>& vi) { for (size_t i = 0; i < vi.size(); ++i) cout << vi[i]; cout<<endl; } int main() { vector<int> vi; vi.push_back(3); vi.push_back(5); sort(vi.begin(), vi.end()); Display(vi); while(next_permutation(vi.begin(), vi.end())) Display(vi); return 0; }
Q2
What will be the output of the following C++ code? #include <iostream> #include <algorithm> using namespace std; int main () { int myints[] = { 10, 20, 30, 30, 20, 10, 10, 20 }; int* pbegin = myints; int* pend = myints + sizeof(myints) / sizeof(int); pend = remove (pbegin, pend, 20); for (int* p = pbegin; p != pend; ++p) cout << ' ' << *p; return 0; }
Q3
How many types of class are there in c++?
Q4
How many variants of tie() function is there?
Q5
Which function is invoked when an unhandled exception is thrown?
Q6
Which function is used to construct heap from given sequence of numbers?
Q7
What will be the output of the following C++ code? #include <iostream> #include <sstream> using namespace std; int main() { stringstream mys(ios :: in | ios :: out); std :: string dat("The double value is : 74.79 ."); mys.str(dat); mys.seekg(-7, ios :: end); double val; mys >> val; val = val*val; mys.seekp(-7,ios::end); mys << val; std :: string new_val = mys.str(); cout << new_val; return 0; }
Q8
What will be the output of the following C++ code? #include <iostream> #include <ios> #include <istream> #include <limits> using namespace std; template <typename CharT> void ignore_line ( basic_istream<CharT>& in ) { in.ignore ( numeric_limits<streamsize> :: max(), in.widen ( '\n' ) ); } int main() { cout << "First input: "; cin.get(); cout << "Clearing cin.\n"; cin.clear(); ignore_line ( cin ); cout << "All done.\n"; }
Q9
What will be the output of the following C++ code? #include <iostream> #include <array> using namespace std; int main(int argc, char const *argv[]) { int arr1[5] = {1,2,3,4,5}; int arr2[5] = {6,7,8,9,10}; arr1.swap(arr2); for(int i=0;i<5;i++) cout<<arr1[i]<<" "; cout<<endl; for(int i=0;i<5;i++) cout<<arr2[i]<<" "; cout<<endl; return 0; }
Q10
What will be the output of the following C++ code? #include <iostream> #include <stack> using namespace std; int main () { stack<int> mystack; mystack.push(10); mystack.push(20); mystack.top() -= 5; cout << mystack.top() << endl; return 0; }
Q11
What will be the output of the following C++ code? #include <typeinfo> #include <iostream> using namespace std; class Myshape { public: virtual void myvirtualfunc() const {} }; class mytriangle: public Myshape { public: virtual void myvirtualfunc() const { }; }; int main() { Myshape Myshape_instance; Myshape &ref_Myshape = Myshape_instance; try { mytriangle &ref_mytriangle = dynamic_cast<mytriangle&>(ref_Myshape); } catch (bad_cast) { cout << "Can't do the dynamic_cast lor!!!" << endl; cout << "Caught: bad_cast exception. Myshape is not mytriangle.\n"; } return 0; }
Q12
Which of the following is correct about tuples?
Q13
What will happen in 'all_of' method if the range is empty?
Q14
What will be the output of the following C++ code? #include <iostream> #include <functional> #include <numeric> using namespace std; int myop (int x, int y) { return x + y + 1; } int main () { int val[] = {1, 2, 3, 4, 5}; int result[5]; partial_sum (val, val + 5, result); for (int i = 0; i < 5; i++) cout << result[i] << ' '; return 0; }
Q15
Pick out the correct statement about string template.
Q16
What will be the output of the following C++ code? #include <iostream> #include <functional> #include <algorithm> using namespace std; int main () { int numbers[] = {1, 2, 3}; int remainders[5]; transform ( numbers, numbers + 5, remainders, bind2nd(modulus<int>(), 2) ); for (int i = 0; i < 5; i++) cout << (remainders[i] == 1 ? "odd" : "even") << "\n"; return 0; }
Q17
Which of the following is the correct syntax of accessing the second element of a pair p?
Q18
What will be the output of the following C++ code? #include <iostream> using namespace std; class Parent { public: Parent (void) { cout << "Parent()\n"; } Parent (int i) { cout << "Parent("<< i << ")\n"; }; Parent (void) { cout << "~Parent()\n"; }; }; class Child1 : public Parent { }; class Child2 : public Parent { public: Child2 (void) { cout << "Child2()\n"; } Child2 (int i) : Parent (i) { cout << "Child2(" << i << ")\n"; } ~Child2 (void) { cout << "~Child2()\n"; } }; int main (void) { Child1 a; Child2 b; Child2 c(42); return 0; }
Q19
What is used to write multi line comment in c++?
Q20
What will be the output of the following C++ code? #include <iostream> using namespace std; class BaseClass { protected: int i; public: BaseClass(int x) { i = x; } ~BaseClass() { } }; class DerivedClass: public BaseClass { int j; public: DerivedClass(int x, int y): BaseClass(y) { j = x; } ~DerivedClass() { } void show() { cout << i << " " << j << endl; } }; int main() { DerivedClass ob(3, 4); ob.show(); return 0; }
Q21
How many bits of memory needed for internal representation of class?
Q22
What will be the output of the following C++ code? #include <iostream> #include <vector> #include <algorithm> using namespace std; int main(int argc, char const *argv[]) { vector <int> v = {1,5,23,90,15,35}; cout<<is_heap(v.begin(), v.end()); make_heap(v.begin(), v.end()); cout<<is_heap(v.begin(), v.end()); }
Q23
Why we use :: template-template parameter?
Q24
To which of the following access specifiers are applicable?
Q25
What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int a = 10, b = 20, c = 30; float d; try { if ((a - b) != 0) { d = c / (a - b); cout << d; } else { throw(a - b); } } catch (int i) { cout<<"Answer is infinite "<<i; } }