C Plus Plus Miscellaneous - Study Mode
[#736] What will be the output of the following C++ code? #include <iostream>
using namespace std
class A
{
public:
A(int n )
{
cout << n
}
}
class B: public A
{
public:
B(int n, double d)
: A(n)
{
cout << d
}
}
class C: public B
{
public:
C(int n, double d, char ch)
: B(n, d)
{
cout <<ch
}
}
int main()
{
C c(5, 4.3, 'R')
return 0
}
Correct Answer
(A) 54.3R
[#737] What will be the output of the following C++ code? #include <iostream>
using namespace std
template <class T>
class Test
{
private:
T val
public:
static int count
Test() {
count++
}
}
template<class T>
int Test<T>::count = 0
int main()
{
Test<int> a
Test<int> b
Test<double> c
cout << Test<int>::count << endl
cout << Test<double>::count << endl
return 0
}
Correct Answer
(A) 2 1
[#738] What is the syntax of an explicit call for a template? Assume the given template function. template<class T, class U>
void func(T a, U b)
{
cout<<a<<" "<<b<<endl
}
Correct Answer
(A) func<int,char>(3,'a')
[#739] Which of the following is a logical unary functor?
Correct Answer
(C) logical_not<T> f
[#740] What will be the output of the following C++ code? #include <iostream>
using namespace std
class Testpm
{
public:
void m_func1()
{
cout << "func1
"
}
int m_num
}
void (Testpm :: *pmfn)() = &Testpm :: m_func1
int Testpm :: *pmd = &Testpm :: m_num
int main()
{
Testpm ATestpm
Testpm *pTestpm = new Testpm
(ATestpm.*pmfn)()
(pTestpm ->* pmfn)()
ATestpm.*pmd = 1
pTestpm ->* pmd = 2
cout << ATestpm.*pmd << endl
<< pTestpm ->* pmd << endl
}
Correct Answer
(D) func1 func1 1 2