81. 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();
}
#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();
}82. 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;
}
#include <iostream>
#include <complex>
using namespace std;
int main()
{
complex <double> cn(3.0, 4.0);
cout<<log(cn)<<endl;
return 0;
}83. Which of the following will return the new element at the end of container?
84. 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;
}
#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;
}85. Which operator is used to compare the values to find min and max?
86. What will not be called when the terminate() is raised in the constructor?
87. 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;
}
#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;
}88. 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;
}
#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;
}89. In which of the following relationship objects of related classes can occur independently?
90. 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;
}
#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;
}Read More Section(C plus plus miscellaneous)
Each Section contains maximum 100 MCQs question on C plus plus miscellaneous. To get more questions visit other sections.
- C plus plus miscellaneous - Section 1
- C plus plus miscellaneous - Section 2
- C plus plus miscellaneous - Section 3
- C plus plus miscellaneous - Section 4
- C plus plus miscellaneous - Section 6
- C plus plus miscellaneous - Section 7
- C plus plus miscellaneous - Section 8
- C plus plus miscellaneous - Section 9
- C plus plus miscellaneous - Section 10
- C plus plus miscellaneous - Section 11
