Question: 1
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main()
{
cout<return 0;
}
Program outputs:
Question: 2
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
templatestruct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator()(const T & val ) { out<};
struct Sequence {
int start;
Sequence(int start):start(start){}
int operator()() { return start++; }
};
struct Odd { bool operator()(int v) { return v%2==0; } };
int main() {
vector v1(10);
vector v2(10);
generate(v1.begin(), v1.end(), Sequence(1));
stable_partition(v1.begin(),v1.end(), Odd());
for_each(v1.begin(), v1.end(), Out(cout) );cout<return 0;
}
Program outputs:
Question: 3
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
templatestruct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator()(const T & val ) { out<};
struct Sequence {
int start;
Sequence(int start):start(start){}
int operator()() { return start++; }
};
struct Odd { bool operator()(int v) { return v%2==0; } };
int main() {
vector v1(10);
vector v2(10);
generate(v1.begin(), v1.end(), Sequence(1));
stable_partition(v1.begin(),v1.end(), Odd());
for_each(v1.begin(), v1.end(), Out(cout) );cout<return 0;
}
Program outputs:
Question: 4
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
int main() {
int t[] = { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
string s[] = { "one", "one", "two", "two", "three","three", "four", "four", "five", "five"};
map m;
for (int i = 0; i < 10; i++) {
m.push_back(pair(t[i], s[i]));
}
for (map::iterator i = m.begin(); i != m.end(); i++) {
cout << i?>first << " ";
}
return 0;
}
Question: 5
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main()
{
cout<return 0;
}
Program outputs: