Question 1 of 25
Hints left: 3
Q1
How many streams are automatically created when executing a program?
Q2
What do container adapter provide to interface?
Q3
What will be the output of the following C++ code? #include <iostream> using namespace std; class BaseClass { int x; public: void setx(int n) { x = n; } void showx() { cout << x ; } }; class DerivedClass : private BaseClass { int y; public: void setxy(int n, int m) { setx(n); y = m; } void showxy() { showx(); cout << y << '\n'; } }; int main() { DerivedClass ob; ob.setxy(10, 20); ob.showxy(); return 0; }
Q4
What is the use of is_array() function in C++?
Q5
What will be the output of the following C++ code? #include <iostream> #include <vector> using namespace std; int main () { vector<int> myvector (5); int* p = myvector.data(); *p = 10; ++p; *p = 20; p[2] = 100; for (unsigned i = 0; i < myvector.size(); ++i) cout << ' ' << myvector[i]; return 0; }
Q6
What is the use of log() function in a complex?
Q7
What will be the output of the following C++ code? #include <iostream> #include <vector> using namespace std; int main () { vector<int> myvector (3); for (unsigned i = 0; i < myvector.size(); i++) myvector.at(i) = i; for (unsigned i = 0; i < myvector.size(); i++) cout << ' ' << myvector.at(i); return 0; }
Q8
Pick out the incorrect method in non-modifying sequence algorithm?
Q9
What is the correct syntax of constructing any using assignment operator?
Q10
What is the correct syntax of defining function template/template functions?
Q11
What is random_device?
Q12
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}; make_heap(v.begin(),v.end()); cout<<v.front(); }
Q13
What are functors in C++?
Q14
Which of the following is correct syntax of making heap from a vector v?
Q15
What will be the output of the following C++ code? #include <iostream> #include <new> using namespace std; int main () { int i, n; int * p; i = 2; p= new (nothrow) int[i]; if (p == 0) cout << "Error: memory could not be allocated"; else { for (n=0; n<i; n++) { p[n] = 5; } for (n = 0; n < i; n++) cout << p[n]; delete[] p; } return 0; }
Q16
What is meant by polymorphism?
Q17
What is mandatory for designing a new container?
Q18
What will be the output of the following C++ code? #include <iostream> using namespace std; long factorial (long a) { if (a > 1) return (a * factorial (a + 1)); else return (1); } int main () { long num = 3; cout << num << "! = " << factorial ( num ); return 0; }
Q19
What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { double a = 10, b = 5, res; char Operator = '/'; try { if (b == 0) throw "Division by zero not allowed"; res = a / b; cout << a << " / " << b << " = " << res; } catch(const char* Str) { cout << "\n Bad Operator: " << Str; } return 0; }
Q20
What will be the output of the following C++ code? #include <vector> #include <algorithm> #include <iostream> #include <iterator> using namespace std; int square(int i) { return i * i; } int main() { vector<int> V, V2; V.push_back(0); V.push_back(1); V.push_back(2); transform(V.begin(), V.end(), back_inserter(V2), square); copy(V2.begin(), V2.end(), ostream_iterator<int>(cout, " ")); cout << endl; }
Q21
Which of the following function is used to get the actual number of elements stored in vector?
Q22
setprecision requires which of the following header file?
Q23
Given the below class, what is the correct syntax of declaring a functor that adds 10 to each of the passed argument? class Add { int x; public: Add(int x){ this->x = x; } int operator()(int a){ return x+a; } };
Q24
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 msg) { cerr << msg << endl; } return 0; }
Q25
What will be the output of the following C++ code? #include <stdexcept> #include <limits> #include <iostream> using namespace std; void func(int c) { if (c < numeric_limits<char> :: max()) throw invalid_argument("MyFunc argument too large."); else { cout<<"Executed"; } } int main() { try { func(256); } catch(invalid_argument& e) { cerr << e.what() << endl; return -1; } return 0; }