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;
}A. 5Index out of bounds
0
B. 40
C. 50
D. 51
Select an option to see the answer and solution.
Which of the following is correct about friend functions?
A. Friend functions use the dot operator to access members of a class using class objects
B. Friend functions can be private or public
C. Friend cannot access the members of the class directly
D. All of the mentioned
Select an option to see the answer and solution.
Which function is used to get the length of a string object?
A. str.length()
B. str.size()
C. str.max_size()
D. both size() and length() function
Select an option to see the answer and solution.
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;
}Select an option to see the answer and solution.
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;
}A. Run-time Error
B. Runs perfectly
C. Segmentation fault
D. Compile-time error
Select an option to see the answer and solution.
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;
}A. 4
B. 2
C. Depends on compiler
D. 8
Select an option to see the answer and solution.
How many types of user-defined data type are in c++?
Select an option to see the answer and solution.
Which is the correct statement about operator overloading?
A. Only arithmetic operators can be overloaded
B. Only non-arithmetic operators can be overloaded
C. Precedence of operators are changed after overlaoding
D. Associativity and precedence of operators does not change
Select an option to see the answer and solution.
Which other keywords are also used to declare the class other than class?
A. struct
B. union
C. object
D. both struct & union
Select an option to see the answer and solution.
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;
}A. 0102030
B. 1020300
C. 3020100
D. error
Select an option to see the answer and solution.
Which of the following is a valid class declaration?
A. class A { int x; };
B. class B { }
C. public class A { }
D. object A { int x; };
Select an option to see the answer and solution.
Which option is best to eliminate the memory problem?
A. use smart pointers
B. use raw pointers
C. use virtual destructor
D. use smart pointers & virtual destructor
Select an option to see the answer and solution.
Pick out the correct statement.
A. virtual functions does not give the ability to write a templated function
B. virtual functions does not give the ability to rewrite a templated function
C. virtual functions does give the ability to write a templated function
D. virtual functions does not give the ability to rewrite a simple function
Select an option to see the answer and solution.
What do we need to use when we have multiple subscripts?
A. operator()
B. operator[]
C. operator
D. operator<>
Select an option to see the answer and solution.
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;
}A. (-240, 128)
B. (240, 128)
C. (240, 120)
D. (240, -122)
Select an option to see the answer and solution.
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;
}A. Hello World
B. Error
C. Segmentation Fault
D. Blank Space
Select an option to see the answer and solution.
Which of the following operator cannot be used to overload when that function is declared as friend function?
Select an option to see the answer and solution.
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;
}A. 1
1
0xbffc9924
1
B. 1
1
1
0xbffc9924
C. 1
0xbffc9924
1
1
D. 0xbffc9924
Select an option to see the answer and solution.
In Linux, how do the heaps and stacks are managed?
A. ram
B. secondary memory
C. virtual memory
D. static memory
Select an option to see the answer and solution.
Which of the following is not a function of complex values?
A. real
B. imag
C. norm
D. cartesian
Select an option to see the answer and solution.