C Plus Plus Miscellaneous - Study Mode

[#921] What will be the output of the following C++ code? #include <iostream>
#include <vector>

using namespace std
int main()
{
vector<int> v
for (int i = 1
i <= 5
i++)
v.push_back(i)
cout<<v.capacity()<<endl
v.shrink_to_fit()
cout<<v.capacity()<<endl
return 0
}
Correct Answer

(B) 8 5

[#922] What will be the output of the following C++ code? #include <iostream>
using namespace std
int funcstatic(int)
{
int sum = 0
sum = sum + 10
return sum
}
int main(void)
{
int r = 5, s
s = funcstatic(r)
cout << s << endl
return 0
}
Correct Answer

(A) 10

[#923] What will be the output of the following C++ code? #include <iostream>
using namespace std
template <class T, int max>
int arrMin(T arr[], int n)
{
int m = max
for (int i = 0
i < n
i++)
if (arr[i] < m)
m = arr[i]
return m
}

int main()
{
int arr1[] = {10, 20, 15, 12}
int n1 = sizeof(arr1)/sizeof(arr1[0])
char arr2[] = {1, 2, 3}
int n2 = sizeof(arr2)/sizeof(arr2[0])
cout << arrMin<int, 10000>(arr1, n1) << endl
cout << arrMin<char, 256>(arr2, n2)
return 0
}
Correct Answer

(A) 10 1

[#924] What will be the output of the following C++ code? #include <iostream>
#include <typeinfo>
using namespace std
class A
{
}
int main()
{
char c
float x
if (typeid(c) != typeid(x))
cout << typeid(c).name() << endl
cout << typeid(A).name()
return 0
}
Correct Answer

(A) c 1A

[#925] What will be the output of the following C++ code? #include <iostream>
#include <map>
using namespace std
int main ()
{
multimap<char, int> mymultimap
mymultimap.insert(make_pair('x', 100))
mymultimap.insert(make_pair('y', 200))
mymultimap.insert(make_pair('y', 350))
mymultimap.insert(make_pair('z', 500))
cout << mymultimap.size() << '
'
return 0
}
Correct Answer

(C) 4