What will happen when you attempt to compile and run the code below, assuming that file test.in contains the following sequence: 1 2 3?
#include
#include
#include
#include
#include
using namespace std;
template
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) {out< int main () { ifstream f("test.in"); list for( ; f.good() ; ) { int i; f>>i; l.push_back(i); } f.close(); for_each(l.begin(), l.end(), Out return 0; } Program will output:
Answer : A
What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
using namespace std;
template
void print(T start, T end)
{
while (start != end)
cout<<*start++;
}
int main ()
{
string t[] = {"one", "two" ,"three" ,"four", "five"};
vector
deque
d1.push_back("zero");
print(d1[0].rbegin(),d1[0].rend());
return 0;
}
Answer : B
What happens when you attempt to compile and run the following code?
include
#include
#include
#include
#include
using namespace std;
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
vector
deque
set
cout< s1.end(), 6); return 0; }
Answer : D
What will happen when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
class A
{
int a;
public:
A(int a) {this?>a = a; c++;}
~A() { c??;}
static int c;
};
int A::c(0);
int main ()
{
A t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8 , 9};
vectorv1(t, t+10);
dequed1(v1.begin(), v1.end());
deque d2;
d2 = d1;
cout< return 0; } How many objects of type A will be created:
Answer : D
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
class A {
int a;
public:
A(int a) : a(a) {}
int getA() const { return a; } void setA(int a) { this?>a = a; }
bool operator==(const A & b) const { return a == b.a; }
};
bool compare(const A & a, const A & b) { return a == b; }
int main () {
int t[] = {1,2,3,3,5,1,2,4,4,5};
vector v (t,t+10);
vector::iterator it = v.begin();
while ( (it = adjacent_find (it, v.end(), compare)) != v.end()) {
cout< } cout<< endl; return 0; }
Answer : B
What happens when you attempt to compile and run the following code?
#include
#include
int main ()
{
std::vector
for(int i = 10; i>0; i??)
{
v1.push_back(i);
}
std::vector
int sum = 0;
while(it != v1.end())
{
sum+=it++;
}
std::cout<<*v1.erase(v1.begin(),v1.end()?3)<<" "< return 0; }
Answer : B
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
class A {
int a;
public:
A(int a) : a(a) {}
int getA() const { return a; } void setA(int a) { this?>a = a; }
};
int main () {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
deque
int number = count(d.begin(), d.end(), 2);
cout<< number< return 0; } Program outputs:
Answer : A