C Plus Plus Miscellaneous - Study Mode
[#896] What will be the output of the following C++ code? #include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std
bool mypredicate (int i, int j)
{
return (i == j)
}
int main ()
{
vector<int> myvector
for (int i = 1
i < 6
i++) myvector.push_back (i * 10)
int myints[] = {10, 20, 30, 40, 1024}
pair<vector<int> :: iterator, int*> mypair
mypair = mismatch (myvector.begin(), myvector.end(), myints)
cout << *mypair.first<<'
'
cout << *mypair.second << '
'
++mypair.first
++mypair.second
return 0
}
Correct Answer
(B) 50 1024
[#897] What will be the output of the following C++ code? #include <iostream>
#include <memory>
#include <string>
using namespace std
int main ()
{
pair <string*, ptrdiff_t>
result = get_temporary_buffer<string>(3)
if (result.second > 0)
{
uninitialized_fill ( result.first, result.first + result.second,
"Hai" )
for (int i=0
i<result.second
i++)
cout << result.first[i]
return_temporary_buffer(result.first)
}
return 0
}
Correct Answer
(C) HaiHaiHai
[#898] What is the correct syntax of constructing any using parameterized constructor?
Correct Answer
(B) any variable_name(value)
[#899] 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)
vector<int> :: const_iterator i
for (i = v.begin()
i != v.end()
++i)
cout << *i << " "
cout<<endl
return 0
}
Correct Answer
(A) 1 2 3 4 5
[#900] What type of Iterator i1 is in the following C++ code snipet? ================ code ================
vector<int>::iterator i1
for (i1=v1.begin()
i1!=v1.end()
++i1)
*i1 = 1
======================================
Correct Answer
(B) Output Iterator