Question 1 of 25
Hints left: 3
Q1
What will be the output of the following C++ code? #include <iostream> using namespace std; int main () { char str[] = "Steve jobs"; int val = 65; char ch = 'A'; cout.width (5); cout << right; cout << val << endl; return 0; }
Q2
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> :: const_iterator i; i = v.begin(); *i = 3; for (i = v.begin(); i != v.end(); ++i) cout << *i << " "; cout<<endl; return 0; }
Q3
What does the size of the vector refers to in c++?
Q4
What happens when only one argument is supplied to reset() function?
Q5
What will be the output of the following C++ code? #include <iostream> using namespace std; template <class T> T max (T &a, T &b) { cout << "Template Called "; return (a > b)? a : b; } template <> int max <int> (int &a, int &b) { cout << "Called "; return (a > b)? a : b; } int main () { int a = 10, b = 20; cout << max <int> (a, b); }
Q6
What will be the output of the following C++ code? #include <iostream> using namespace std; class Base { public: virtual void print() const = 0; }; class DerivedOne : virtual public Base { public: void print() const { cout << "1"; } }; class DerivedTwo : virtual public Base { public: void print() const { cout << "2"; } }; class Multiple : public DerivedOne, DerivedTwo { public: void print() const { DerivedTwo::print(); } }; int main() { Multiple both; DerivedOne one; DerivedTwo two; Base *array[ 3 ]; array[ 0 ] = &both; array[ 1 ] = &one; array[ 2 ] = &two; for ( int i = 0; i < 3; i++ ) array[ i ] -> print(); return 0; }
Q7
Which statement is used to catch all types of exceptions?
Q8
Pick the correct statement.
Q9
What will be the output of the following C++ code? #include <iostream> using namespace std; class vec { public: vec(float f1, float f2) { x = f1; y = f2; } vec() { } float x; float y; }; vec addvectors(vec v1, vec v2); int main() { vec v1(3, 6); vec v2(2, -2); vec v3 = addvectors(v1, v2); cout << v3.x << ", " << v3.y << endl; } vec addvectors(vec v1, vec v2) { vec result; result.x = v1.x + v2.x; result.y = v1.y + v2.y; return result; };
Q10
What does the sequence adaptor provide?
Q11
What is the correct syntax of declaring an array class?
Q12
What will be the output of the following C++ code? #include <iostream> #include <algorithm> #include <vector> using namespace std; int main () { int myints[] = {1, 2, 3, 4 ,5}; vector<int> v(myints, myints + 5); v.push_back(33); push_heap (v.begin(),v.end()); cout << v.front() << '\n'; sort_heap (v.begin(),v.end()); return 0; }
Q13
What do all STL containers define?
Q14
What will be the output of the following C++ code? #include <iostream> #include <typeinfo> #include <exception> using namespace std; class base { virtual void f(){} }; class derived : public base {}; int main () { try { base* a = new base; base* b = new derived; cout << typeid(*a).name() <v '\t'; cout << typeid(*b).name(); } catch (exception& e) { cout << "Exception: " << e.what() << endl; } return 0; }
Q15
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { int a; public: virtual void func() = 0; }; class B: public A { public: void func(){ cout<<"Class B"<<endl; } }; int main(int argc, char const *argv[]) { B b; b.func(); return 0; }
Q16
Which is similar to template specialization?
Q17
Which function is used to check whether a character is hexadecimal?
Q18
What will be the output of the following C++ code? #include <iostream> #include <array> using namespace std; int main(int argc, char const *argv[]) { array<int, 10> arr1 = {1,2,3,4,5}; array<int, 5> arr2 = {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; }
Q19
Which function is used to return the minimum element in the range?
Q20
What will be the output of the following C++ code? #include <iostream> #include <complex> using namespace std; int main() { complex <double> cn(3.0, 5.0); cout<<"Absolute value is: "<<abs(cn)<<endl; return 0; }
Q21
To use command line arguments in C++, how many parameters are passed to the main function?
Q22
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { int a; public: virtual void func() = 0; }; class B: public A { public: void func(){ cout<<"Class B"<<endl; } }; int main(int argc, char const *argv[]) { A a; a.func(); return 0; }
Q23
The destination statement for the goto label is identified by what label?
Q24
Given below classes which of the following are the possible row entries in vtable of D2 class? class Base { public: virtual void function1() {}; virtual void function2() {}; }; class D1: public Base { public: virtual void function1() {}; }; class D2: public Base { public: virtual void function2() {}; };
Q25
Pick out the correct statement about sequence point.