What will be the output of the following C++ code?
#include <iostream>
using namespace std;
template <class T>
class XYZ
{
public:
void putPri();
static T ipub;
private:
static T ipri;
};
template <class T>
void XYZ<T>::putPri()
{
cout << ipri++ << endl;
}
template <class T> T XYZ<T>::ipub = 1;
template <class T> T XYZ<T>::ipri = 1.2;
int main()
{
XYZ<int> a;
XYZ<float> b;
a.putPri();
cout << a.ipub << endl;
b.putPri();
}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> cn(3.0, 4.0);
cout<<log(cn)<<endl;
return 0;
}A. 1.60944
B. (1.60944,0.927295)
C. 0.927295
D. 1.60944 + 0.927295
Select an option to see the answer and solution.
Which of the following will return the new element at the end of container?
A. front
B. back
C. push_back
D. pop_back
Select an option to see the answer and solution.
How are many number of characters available in newname.txt?
#include <stdio.h>
int main ()
{
FILE * p;
int n = 0;
p = fopen ("newname.txt", "rb");
if (p == NULL)
perror ("Error opening file");
else
{
while (fgetc(p) != EOF)
{
++n;
}
if (feof(p))
{
printf ("%d\n", n);
}
else
puts ("End-of-File was not reached.");
fclose (p);
}
return 0;
}A. 10
B. 15
C. Depends on the text file
D. 34
Select an option to see the answer and solution.
Which operator is used to compare the values to find min and max?
Select an option to see the answer and solution.
What will not be called when the terminate() is raised in the constructor?
A. main()
B. class
C. destructor
D. constructor
Select an option to see the answer and solution.
What will be the output of the following C++ code?
#include <new>
#include <iostream>
using namespace std;
struct A
{
virtual ~A() { };
void operator delete(void* p)
{
cout << "A :: operator delete" << endl;
}
};
struct B : A
{
void operator delete(void* p)
{
cout << "B :: operator delete" << endl;
}
};
int main()
{
A* ap = new B;
delete ap;
}A. A::operator delete
B. B::operator delete
C. Both A::operator delete & B::operator delete
D. A:operator new
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 = 5;
int b = 5;
auto check = [&a]()
{
a = 10;
b = 10;
}
check();
cout<<"Value of a: "<<a<<endl;
cout<<"Value of b: "<<b<<endl;
return 0;
}A. Value of a: 5
B. Value of a: 10
C. Error
D. Segmentation fault
Select an option to see the answer and solution.
In which of the following relationship objects of related classes can occur independently?
A. Aggregation
B. Association
C. Composition
D. Both Aggregation an Association
Select an option to see the answer and solution.
What will be the output of the following C++ code?
#include <iostream>
#include <array>
using namespace std;
int main(int argc, char const *argv[])
{
array<int, 5> arr1;
arr1.fill(2);
for(int i=0;i<5;i++)
cout<<arr1[i];
cout<<endl;
return 0;
}A. 22222
B. 20000
C. 00002
D. 20002
Select an option to see the answer and solution.
What is meant by hash tables in C++?
A. Array data structure
B. Keyed array data structure
C. Data structure
D. Linear probing
Select an option to see the answer and solution.
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;
myvector.push_back(10);
myvector.push_back(25);
myvector.push_back(40);
myvector.push_back(55);
vector<int> :: iterator it = find_if (myvector.begin(),
myvector.end(), IsOdd);
cout << *it << '\n';
return 0;
}Select an option to see the answer and solution.
Given below classes which of the following are the possible row entries in vtable of Base class?
class Base
{
public:
virtual void function1() {};
virtual void function2() {};
};
class D1: public Base
{
public:
virtual void function1() {};
};
class D2: public Base
{
public:
virtual void function2() {};
};A. Base::function1() and Base::function2()
B. Base::function1() and D1::function2()
C. D1::function1() and Base::function2()
D. D1::function1() and D1::function2() or D2::function1() and D2::function2()
Select an option to see the answer and solution.
Which of the following is the correct syntax of declaring a complex number?
A. complex variable_name<type>;
B. complex<type> variable_name;
C. Complex<type> variable_name;
D. None of the above
Select an option to see the answer and solution.
What is the use of the flip function in bitset?
A. Used to flip bit(s) in a bitset
B. Used to flip a bit in a bitset
C. Used to flip all bits to 1
D. Used to flip alternate bits
Select an option to see the answer and solution.
What do input and output objects support?
A. Terminated sequences
B. Extracted sequences
C. Null-terminated sequences
D. Terminated & Extracted sequences
Select an option to see the answer and solution.
What is the use of log() function in a complex?
A. To calculate the log of the imaginary part of a complex number
B. To calculate the log of rethe al part of a complex number
C. To calculate the log of a complex number
D. To calculate the log of the argument of a complex number
Select an option to see the answer and solution.
What is meant by polymorphism?
A. class having many forms
B. class having only single form
C. class having two forms
D. class having four forms
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()
{
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;
}A. 10
B. 2
C. Bad Operator
D. 10 / 5 = 2
Select an option to see the answer and solution.
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;
}A. 10 20 0 100 0
B. 10 20 0 100
C. 10 20 0
D. 10 20
Select an option to see the answer and solution.