C Plus Plus Miscellaneous - Study Mode
[#846] What will be the output of the following C++ code? #include <iostream>
using namespace std
template <typename T, typename U>
void squareAndPrint(T x, U y)
{
cout << x << x * x << endl
cout << y << " " << y * y << endl
}
int main()
{
int ii = 2
float jj = 2.1
squareAndPrint<int, float>(ii, jj)
}
Correct Answer
(B) 24 2.1 4.41
[#847] What will be the output of the following C++ code? #include <iostream>
#include <list>
using namespace std
int main ()
{
list<int> mylist
list<int> :: iterator it1, it2
for (int i = 1
i < 10
++i) mylist.push_back(i * 1)
it1 = it2 = mylist.begin()
advance (it2, 6)
++it1
it1 = mylist.erase (it1)
it2 = mylist.erase (it2)
++it1
--it2
mylist.erase (it1, it2)
for (it1 = mylist.begin()
it1 != mylist.end()
++it1)
cout << ' ' << *it1
return 0
}
Correct Answer
(C) 1 3 6 8 9
[#848] What will be the output of the following C++ code? #include <iostream>
using namespace std
class Base
{
public:
Base(){}
~Base(){}
protected:
private:
}
class Derived:public Base
{
public:
Derived(){}
Derived(){}
private:
protected:
}
int main()
{
cout << "The program exceuted" << endl
}
Correct Answer
(B) Error
[#849] What will be the output of the following C++ code? #include <iostream>
#include <algorithm>
using namespace std
int main ()
{
cout << min(2, 1) << ' '
cout << min('m','m') << '
'
return 0
}
Correct Answer
(C) 1 m
[#850] What will be the output of the following C++ code? #include <iostream>
#include<type_traits>
using namespace std
class Base
{
public:
void function1() {}
void function2() {}
}
int main()
{
Base b
cout<<sizeof(b)
return 0
}
Correct Answer
(C) 1