Question 1 of 25
Hints left: 3
Q1
What will be the output of the following C++ code? #include <iostream> #include <algorithm> #include <vector> using namespace std; bool myfunction (int i, int j) { return (i < j); } struct myclass { bool operator() (int i, int j) { return (i < j); } } myobject; int main () { int myints[] = {10, 9, 8}; vector<int> myvector (myints, myints + 3); sort (myvector.begin(), myvector.begin() + 2); sort (myvector.begin() + 1, myvector.end(), myfunction); sort (myvector.begin(), myvector.end(), myobject); for (vector<int> :: iterator it = myvector.begin(); it != myvector.end(); ++it) cout << ' ' << *it; return 0; }
Q2
What will be the output of the following C++ code? #include <iostream> #include <map> using namespace std; int main () { try { map<char, int> mymap; map<char, int> :: iterator it; mymap['a'] = 50; mymap['b'] = 100; mymap['c'] = 150; mymap['d'] = 200; it = mymap.find('b'); mymap.erase (it); mymap.erase (mymap.find('d')); cout << mymap.find('a') -> second << '\n'; } catch (...) { cout << "Unknown exception: " << endl; } return 0; }
Q3
What is the use of empty() function in array classes?
Q4
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; }
Q5
What is the use of RAII in c++ programming?
Q6
What will be the output of the following C++ code? #include <iostream> using namespace std; class MyInterface { public: virtual void Display() = 0; }; class Class1 : public MyInterface { public: void Display() { int a = 5; cout << a; } }; class Class2 : public MyInterface { public: void Display() { cout <<" 5" << endl; } }; int main() { Class1 obj1; obj1.Display(); Class2 obj2; obj2.Display(); return 0; }
Q7
What will be the output of the following C++ code? #include <iostream> #include <utility> using namespace std; int main () { pair <int,int>p; p = make_pair(1,2); cout<<"Pair(first,second) = ("<<p.first<<","<<p.second<<")\n"; return 0; }
Q8
How many vector container properties are there in c++?
Q9
What will be the output of the following C++ code? #include <iostream> #include <cctype> using namespace std; int main(int argc, char const *argv[]) { char arr[12] = "H3ll0\tW0r1d"; for(int i=0;i<12;i++) { cout<<(bool)isprint(arr[i]); } }
Q10
What will be the output of the following C++ code? #include <iostream> using namespace std; class BaseClass { public: virtual void myFunction() { cout << "1"; } }; class DerivedClass1 : public BaseClass { public: void myFunction() { cout << "2"; } }; class DerivedClass2 : public DerivedClass1 { public: void myFunction() { cout << "3"; } }; int main() { BaseClass *p; BaseClass ob; DerivedClass1 derivedObject1; DerivedClass2 derivedObject2; p = &ob; p -> myFunction(); p = &derivedObject1; p -> myFunction(); p = &derivedObject2; p -> myFunction(); return 0; }
Q11
What is bitset in C++?
Q12
What kind of error can arise when there is a problem with memory?
Q13
Which function is used to check whether a character is a tab or space?
Q14
What will be the output of the following C++ code? #include <iostream> #include <exception> using namespace std; class myexception: public exception { virtual const char* what() const throw() { return "My exception"; } } myex; int main () { try { throw myex; } catch (exception& e) { cout << e.what() << endl; } return 0; }
Q15
Which header file is required to use tuples in your program?
Q16
What is another name of full specialization?
Q17
What does this template function indicates? ================== template<class T> void func(T a) { cout<<a; } ==================
Q18
What is the use of tie() function?
Q19
Which of the following(s) can be used to access the last element of a vector v?
Q20
Pick out the correct statement about permutation.
Q21
What will be the output of the following C++ code? #include <iostream> using namespace std; int array[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; void swap(int x, int y) { int temp = array[x]; array[x] = array[y]; array[y] = temp; return; } void printArray(int size) { int i; for (i = 0; i < size; i++) cout << array[i] << " "; cout << endl; return; } void permute(int k, int size) { int i; if (k == 0) printArray(size); else { for (i = k - 1;i >= 0;i--) { swap(i, k - 1); permute(k - 1, size); swap(i, k - 1); } } return; } int main() { permute(3, 3); return 0; }
Q22
What will happen when a programs throws any other type of exception other than specified?
Q23
Which of the following is correct about any() function in bitset?
Q24
How many groups of output of operation are there in c++?
Q25
What can be passed by non-type template parameters during compile time?