C Plus Plus Miscellaneous - Study Mode
[#726] What will be the output of the following C++ code? #include <iostream>
#include <utility>
using namespace std
int main ()
{
pair <int,int> p(1,2)
cout<<"Pair(first,second) = ("<<p.first<<","<<p.second<<")
"
return 0
}
Correct Answer
(A) Pair(first,second) = (1,2)
[#727] What will be the output of the following C++ code? #include <iostream>
using namespace std
template <typename T, int count>
void loopIt(T x)
{
T val[count]
for(int ii = 0
ii < count
ii++)
{
val[ii] = x++
cout << val[ii] << endl
}
}
int main()
{
float xx = 2.1
loopIt<float, 3>(xx)
}
Correct Answer
(C) 2.1 3.1 4.1
[#728] What will be the output of the following C++ code? #include <iostream>
#include <functional>
#include <algorithm>
using namespace std
int main ()
{
int numbers[] = {3, -4, -5}
transform ( numbers, numbers + 3, numbers, negate<int>() )
for (int i = 0
i < 3
i++)
cout << numbers[i] << " "
}
Correct Answer
(D) -3 4 5
[#729] What will be the output of the following C++ code? #include <iostream>
using namespace std
template<typename type>
class Test
{
public:
Test()
{
}
~Test()
{
}
type Funct1(type Var1)
{
return Var1
}
type Funct2(type Var2)
{
return Var2
}
}
int main()
{
Test<int> Var1
Test<float> Var2
cout << Var1.Funct1(200) << endl
cout << Var2.Funct2(3.123) << endl
return 0
}
Correct Answer
(A) 200 3.123
[#730] What will be the output of the following C++ code? #include <iostream>
#include <functional>
#include <algorithm>
using namespace std
int main ()
{
int first[] = {10, 40, 90}
int second[] = {1, 2, 3}
int results[5]
transform ( first, first + 5, second, results, divides<int>())
for (int i = 0
i < 3
i++)
cout << results[i] << " "
return 0
}
Correct Answer
(C) 10 20 30