Question 1 of 25
Hints left: 3
Q1
Which of the following is correct about friend functions?
Q2
Which function is used to get the length of a string object?
Q3
Which option is best to eliminate the memory problem?
Q4
What will be the output of the following C++ code? #include <iostream> #include <complex> using namespace std; int main() { complex<double> c1(4.0,3.0); cout << "c1: " << c1; complex<float> c2(polar(5.0,0.75)); cout << c1 + complex<double>(c2.real(),c2.imag()); return 0; }
-
A
-
B
-
C
-
D
Q5
What will be the output of the following C++ code? #include <iostream> using namespace std; class sample { public: int x, y; sample() {}; sample(int, int); sample operator + (sample); }; sample::sample (int a, int b) { x = a; y = b; } sample sample::operator+ (sample param) { sample temp; temp.x = x + param.x; temp.y = y + param.y; return (temp); } int main () { sample a (4,1); sample b (3,2); sample c; c = a + b; cout << c.x << "," << c.y; return 0; }
Q6
What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int i; enum month { JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,DEC }; for (i = JAN; i <= DEC; i++) cout << i; return 0; }
Q7
Which is the correct statement about operator overloading?
Q8
Which of the following operator cannot be used to overload when that function is declared as friend function?
Q9
What will be the output of the following C++ code? #include <iostream> using namespace std; int main () { int a; int * ptr_b; int ** ptr_c; a = 1; ptr_b = &a; ptr_c = &ptr_b; cout << a << "\n"; cout << *ptr_b << "\n"; cout << *ptr_c << "\n"; cout << **ptr_c << "\n"; return 0; }
Q10
Which of the following is a valid class declaration?
Q11
Which of the following is not a function of complex values?
Q12
What do we need to use when we have multiple subscripts?
Q13
In Linux, how do the heaps and stacks are managed?
Q14
What will be the output of the following C++ code? #include <iostream> using namespace std; const int SIZE = 10; class safe { private: int arr[SIZE]; public: safe() { register int i; for (i = 0; i < SIZE; i++) { arr[i] = i; } } int &operator[](int i) { if (i > SIZE) { cout << "Index out of bounds" <<endl; return arr[0]; } return arr[i]; } }; int main() { safe A; cout << A[5]; cout << A[12]; return 0; }
Q15
What will be the output of the following C++ code? #include <iostream> using namespace std; class S { int m; public: #define MAC(S::m) }; int main(int argc, char const *argv[]) { cout<<"Hello World"; return 0; }
Q16
What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int x; int *p; x = 5; p = &x; cout << *p; return 0; }
Q17
What will be the output of the following C++ code? #include <iostream> #include <complex> using namespace std; int main() { complex<double> c1(4.0, 16.0), c2; c2 = pow(c1, 2.0); cout << c2; return 0; }
Q18
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { static int a; public: void show() { a++; cout<<"a: "<<a<<endl; } void operator.() { cout<<"Objects are added\n"; } }; class B { public: }; int main(int argc, char const *argv[]) { A a1, a2; return 0; }
Q19
What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int a, b; int* c; c = &a; a = 200; b = 200; *c = 100; b = *c; cout << *c << " " << b; return 0; }
Q20
Pick out the correct statement.
Q21
How many types of user-defined data type are in c++?
Q22
How many approaches are used for operator overloading?
Q23
What will be the output of the following C++ code? #include <iostream> using namespace std; const int limit = 4; class safearray { private: int arr[limit]; public: int& operator [](int n) { if (n == limit - 1) { int temp; for (int i = 0; i < limit; i++) { if (arr[n + 1] > arr[n]) { temp = arr[n]; arr[n] = arr[n + 1]; arr[n + 1] = temp; } } } return arr[n]; } }; int main() { safearray sa1; for(int j = 0; j < limit; j++) sa1[j] = j*10; for(int j = 0; j < limit; j++) { int temp = sa1[j]; cout << "Element " << j << " is " << temp; } return 0; }
Q24
Which other keywords are also used to declare the class other than class?
Q25
What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int x = 9; int* p = &x; cout << sizeof(p); return 0; }