C Plus Plus Miscellaneous - Study Mode
[#891] What will be the output of the following C++ code? #include <iostream>
using namespace std
int main()
{
int i
for (i = 0
i < 10
i++)
{
cout << i
}
return 0
}
Correct Answer
(B) 10
[#892] What will be the output of the following C++ code? #include <iostream>
using namespace std
template <typename T = float, int count = 3>
T multIt(T x)
{
for(int ii = 0
ii < count
ii++)
{
x = x * x
}
return x
}
int main()
{
float xx = 2.1
cout << xx << ": " << multIt<>(xx) << endl
}
Correct Answer
(C) 2.1: 378.228
[#893] What will be the output of the following C++ code? #include<iostream>
using namespace std
int main()
{
int a = 5
auto check = [=]()
{
a = 10
}
check()
cout<<"Value of a: "<<a<<endl
return 0
}
Correct Answer
(C) Error
[#894] What will be the output of the following C++ code? #include <iostream>
#include <algorithm>
#include <vector>
using namespace std
int main ()
{
vector<int> first (5, 10)
vector<int> second (5, 33)
vector<int>::iterator it
swap_ranges(first.begin() + 1, first.end() - 1, second.begin())
cout << " first contains:"
for (it = first.begin()
it != first.end()
++it)
cout << " " << *it
cout << "
second contains:"
for (it = second.begin()
it != second.end()
++it)
cout << " " << *it
return 0
}
Correct Answer
(A) first contains: 10 33 33 33 10 second contains: 10 10 10 33 33
[#895] What will be the output of the following C++ code? #include <vector>
#include <iostream>
#include <typeinfo>
#include <stdexcept>
using namespace std
int main()
{
vector<int> vec
vec.push_back(10)
int i = vec[100]
try {
i = vec[0]
cout << i << endl
}
catch (exception &e)
{
cout << "Caught: " << e.what( ) << endl
cout << "Type: " << typeid( e ).name( ) << endl
}
catch (...)
{
cout << "Unknown exception: " << endl
}
return 0
}
Correct Answer
(A) 10