Question 1 of 25
Hints left: 3
Q1
What will be the output of the following C++ code? #include <iostream> using namespace std; struct X; struct Y { void f(X*); }; struct X { private: int i; public: void initialize(); friend void g(X* , int); friend void Y :: f(X*); friend struct Z; friend void h(); }; void X :: initialize() { i = 0; } void g(X* x, int i) { x -> i = i; } void Y :: f(X * x) { x -> i = 47; cout << x->i; } struct Z { private: int j; public: void initialize(); void g(X* x); }; void Z::initialize() { j = 99; } void Z::g(X* x) { x -> i += j; } void h() { X x; x.i = 100; cout << x.i; } int main() { X x; Z z; z.g(&x); cout << "Data accessed"; }
Q2
What will be the output of the following C++ code? #include <iostream> using namespace std; int main () { int a = 100; double b = 3.14; cout << a; cout << endl; cout << b << endl << a * b; endl (cout); return 0; }
Q3
What will be the output of the following C++ code? #include <iostream> using namespace std; template <class T> inline T square(T x) { T result; result = x * x; return result; }; template <> string square<string>(string ss) { return (ss+ss); }; int main() { int i = 2, ii; string ww("A"); ii = square<int>(i); cout << i << ": " << ii; cout << square<string>(ww) << ":" << endl; }
Q4
What will be the output of the following C++ code? #include <iostream> using namespace std; template<class T = float, int i = 5> class A { public: A(); int value; }; template<> class A<> { public: A(); }; template<> class A<double, 10> { public: A(); }; template<class T, int i> A<T, i>::A() : value(i) { cout << value; } A<>::A() { cout << "default"; } A<double, 10>::A() { cout << "10" << endl; } int main() { A<int, 6> x; A<> y; A<double, 10> z; }
Q5
Which exception is thrown by dynamic_cast?
Q6
What will be the output of the following C++ code? #include <iostream> #include <string> #include <cstdlib> using namespace std; template<class T> class A { public: T func(T a, T b){ return a/b; } }; int main(int argc, char const *argv[]) { A <float>a1; cout<<a1.func(3,2)<<endl; cout<<a1.func(3.0,2.0)<<endl; return 0; }
Q7
What is the use of has_value() function in any container?
Q8
Where are allocators used?
Q9
Which function allows you to set minimum width for the next input?
Q10
What will be the output of the following C++ code? #include <iostream> #include <algorithm> #include <vector> using namespace std; int main () { int myints[] = { 10, 20, 30 ,40 }; int * p; p = find (myints, myints + 4, 30); --p; cout << *p << '\n'; return 0; }
Q11
Which is a constant defined in <cstdlib> header file?
Q12
Which container is used to store elements as key-value pair?
Q13
Which constructor will initialize the base class data member?
Q14
What will be the output of the following C++ code? #include <iostream> #include <vector> using namespace std; int main () { unsigned int i; vector<int> first; vector<int> second (4, 100); vector<int> third (second.begin(), second.end()); vector<int> fourth (third); int myints[] = {16, 2, 77, 29}; vector<int> fifth (myints, myints + sizeof(myints) / sizeof(int) ); for (vector<int> :: iterator it = fifth.begin(); it != fifth.end(); ++it) cout << ' ' << *it; return 0; }
Q15
What does size() function returns?
Q16
Which word is used to stop the unpacking of a value in a tuple?
Q17
How many categories of iterators are there in c++?
Q18
If inner catch block is unable to handle the exception thrown then . . . . . . . .
Q19
What will be the output of the following C++ code? #include <iostream> using namespace std; struct A { int i; char j; float f; void func(); }; void A :: func() {} struct B { public: int i; char j; float f; void func(); }; void B :: func() {} int main() { A a; B b; a.i = b.i = 1; a.j = b.j = 'c'; a.f = b.f = 3.14159; a.func(); b.func(); cout << "Allocated"; return 0; }
Q20
What is the use of checked iterators?
Q21
What will be the output of the following C++ code? #include <iostream> #include <memory> #include <algorithm> using namespace std; int main () { int numbers[] = {1, 5, 4, 5}; pair <int*, ptrdiff_t> result = get_temporary_buffer<int>(4); if (result.second > 0) { uninitialized_copy (numbers, numbers + result.second, result.first); sort (result.first, result.first + result.second); for (int i = 0; i < result.second; i++) cout << result.first[i] << " "; return_temporary_buffer (result.first); } return 0; }
Q22
What will be the output of the following C++ code? #include <iostream> #include <iterator> #include <list> using namespace std; int main () { list<int> mylist; for (int i = 0; i < 5; i++) mylist.push_back (i * 20); list<int> :: iterator first = mylist.begin(); list<int> :: iterator last = mylist.end(); cout << distance(first, last) << endl; return 0; }
Q23
What will be the output of the following C++ code? #include <iostream> using namespace std; double division(int a, int b) { if (b == 0) { throw "Division by zero condition!"; } return (a / b); } int main () { int x = 50; int y = 0; double z = 0; try { z = division(x, y); cout << z << endl; } catch (const char* msg) { cerr << msg << endl; } return 0; }
Q24
How many items are presented in the associate container?
Q25
Which of the following header files is required for creating and reading data files?