C Plus Plus Miscellaneous - Study Mode
[#646] What is the correct syntax for declaring an allocator?
Correct Answer
(A) template < class T > class allocator
[#647] What will be the output of the following C++ code? #include <stdio.h>
int main ()
{
freopen ("myfile.txt", "w", stdout)
printf ("This sentence is redirected to a file")
fclose (stdout)
return 0
}
Correct Answer
(C) This sentence is redirected to a file
[#648] What will be the output of the following C++ code? #include <iostream>
#include <iterator>
#include <list>
using namespace std
int main ()
{
list<int> mylist
for (int i = 0
i < 10
i++)
mylist.push_back (i * 10)
list<int> :: iterator it = mylist.begin()
advance (it, 5)
cout << *it << endl
return 0
}
Correct Answer
(C) 50
[#649] What will be the output of the following C++ code? #include<iostream>
using namespace std
int main()
{
int a = 5
auto check = [](int x)
{
if(x == 0)
return false
else
return true
}
cout<<check(a)<<endl
return 0
}
Correct Answer
(B) 1
[#650] What will be the output of the following C++ code? #include <iostream>
#include <algorithm>
#include <vector>
using namespace std
bool mygreater (int i,int j)
{
return (i > j)
}
int main ()
{
int myints[] = {10, 20, 30, 30, 20, 10, 10, 20}
vector<int> v(myints, myints + 8)
pair<vector<int> :: iterator, vector<int> :: iterator> bounds
sort (v.begin(), v.end())
bounds = equal_range (v.begin(), v.end(), 20)
cout << (bounds.first - v.begin())
cout << " and " << (bounds.second - v.begin()) << '
'
return 0
}
Correct Answer
(A) 3 and 6