C Plus Plus Miscellaneous - Study Mode

[#666] What will be the output of the following C++ code? #include <iostream>
#include <string>
#include <cstdlib>
using namespace std

template<class T>
T func(T a)
{
cout<<a

return a

}

template<class U>
void func(U a)
{
cout<<a

}

int main(int argc, char const *argv[])
{
int a = 5

int b = func(a)

return 0

}
Correct Answer

(C) Error

[#667] What will be the output of the following C++ code? #include<iostream>
#include<any>
#include<string>
using namespace std

int main()
{
string s = "Hello World"

any var(s)

cout<<any_cast<string>(var)<<endl

return 0

}
Correct Answer

(D) Nothing is printed

[#668] What will be the output of the following C++ code? #include <iostream>
#include <vector>
using namespace std

int main ()
{
vector<bool> mask

mask.push_back(true)

mask.flip()

cout << boolalpha

for (unsigned i = 0

i < mask.size()

i++)
cout << mask.at(i)

return 0

}
Correct Answer

(A) false

[#669] What will be the output of the following C++ code? #include <iostream>
#include <string>
#include <bitset>
using namespace std

int main ()
{
string mystring

bitset<4> mybits

mybits.set()

mystring = mybits.to_string<char, char_traits<char>,
allocator<char> >()

cout << mystring << endl

return 0

}
Correct Answer

(D) 1111

[#670] What will be the output of the following C++ code? #include <iostream>
using namespace std

class BaseClass
{
protected:
int i

public:
BaseClass(int x)
{
i = x

}
~BaseClass()
{
}
}

class DerivedClass: public BaseClass
{
int j

public:
DerivedClass(int x, int y): BaseClass(y)
{
j = x

}
~DerivedClass()
{
}
void show()
{
cout << i << " " << j << endl

}
}

int main()
{
DerivedClass ob(3, 4)

ob.show()

return 0

}
Correct Answer

(B) 4 3