Question 1 of 25
Hints left: 3
Q1
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 <int>a1; cout<<a1.func(3,2)<<endl; cout<<a1.func(3.0,2.0)<<endl; return 0; }
Q2
Which function is used to check whether a character is printable on console?
Q3
What will be the output of the following C++ code? #include <iostream> using namespace std; void square (int *x) { *x = (*x + 1) * (*x); } int main ( ) { int num = 10; square(&num); cout << num; return 0; }
Q4
What will be the type of output of vector cross product?
Q5
What will be the output of the following C++ code? #include <stdio.h> #include <stdlib.h> #include <time.h> int main () { srand (time(NULL)); printf ("Random number: %d\n", rand() % 100); srand (1); return 0; }
Q6
What will be the output of the following C++ code? #include <iostream> #include <iterator> using namespace std; int main () { try { double value1, value2; istream_iterator<double> eos; istream_iterator<double> iit (cin); if (iit != eos) value1 = *iit; iit++; if (iit != eos) value2 = *iit; cout << (value1 * value2) << endl; } catch (...) { cout << "Unknown exception: " << endl; } return 0; }
Q7
Which keyword is used to declare the min and max functions?
Q8
What may be the name of the parameter that the template should take?
Q9
Which is called on allocating the memory for the array of objects?
Q10
What will be the output of the following C++ code? #include <iostream> #include <algorithm> #include <vector> using namespace std; bool IsOdd (int i) { return (i % 2) == 1; } int main () { vector<int> myvector; for (int i = 1; i < 10; ++i) myvector.push_back(i); vector<int> :: iterator bound; bound = partition (myvector.begin(), myvector.end(), IsOdd); for (vector<int> :: iterator it = myvector.begin(); it != bound; ++it) cout << ' ' << *it; return 0; }
Q11
What is meant by sequence point?
Q12
How many types of container classes are there in c++?
Q13
What is the syntax of inheritance of class?
Q14
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); } int main () { int myints[] = {9, 8, 7, 6, 5}; vector<int> myvector (myints, myints + 5); partial_sort (myvector.begin(), myvector.begin() + 3, myvector.end()); partial_sort (myvector.begin(), myvector.begin() + 2, myvector.end(), myfunction); for (vector<int> :: iterator it = myvector.begin(); it != myvector.end(); ++it) cout << ' ' << *it; return 0; }
Q15
What is the difference between begin() and rbegin()?
Q16
What is the use of get() function in tuples?
Q17
Which of the following is correct about the second parameter of the main function?
Q18
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<<"Complex number with magnitude "<<abs(cn)<<" and phase angle "<<arg(cn)<<" is: "<<polar(abs(cn), arg(cn))<<endl; return 0; }
Q19
Which header file is required to use complex class in your program?
Q20
What will be the output of the following C++ code? #include <stdio.h> int main () { FILE * p; int c; int n = 0; p = fopen ("myfile.txt", "r"); if (p == NULL) perror ("Error opening file"); else { do { c = getc (p); if (c == '$') n++; } while (c != EOF); fclose (p); printf ("%d\n", n); } return 0; }
Q21
What will be the output of the following C++ code? #include <iostream> using namespace std; template <class T> class A { public: A(int a): x(a) {} protected: int x; }; template <class T> class B: public A<char> { public: B(): A<char>::A(100) { cout << x * 2 << endl; } }; int main() { B<char> test; return 0; }
Q22
Where does the member should be defined if it is used in the program?
Q23
What will be the output of the following C++ code? #include <stdexcept> #include <limits> #include <iostream> using namespace std; void MyFunc(char c) { if (c < numeric_limits<char>::max()) return invalid_argument; } int main() { try { MyFunc(256); } catch(invalid_argument& e) { cerr << e.what() << endl; return -1; } return 0; }
Q24
What will be the output of the following C++ code? #include <iostream> #include <algorithm> #include <vector> using namespace std; bool IsOdd (int i) { return (i%2)==1; } int main () { vector<int> v; for (int i=1; i<=10; ++i) v.push_back(i); vector<int>::iterator bound; bound = partition (v.begin(), v.end(), IsOdd); for (vector<int>::iterator it=v.begin(); it!=bound; ++it) cout << ' ' << *it; cout << '\n'; for (vector<int>::iterator it=bound; it!=v.end(); ++it) cout << ' ' << *it; cout << '\n'; return 0; }
Q25
What will be the output of the following C++ code? #include <iostream> using namespace std; template<int n> struct funStruct { static const int val = 2*funStruct<n-1>::val; }; template<> struct funStruct<0> { static const int val = 1 ; }; int main() { cout << funStruct<10>::val << endl; return 0; }