NO.1 What happens when you attempt to compile and run the following code?
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
struct Add {
int operator()(int & a, int & b) {
return a+b;
}
};
int main() {
int t[]={1,2,3,4,5,6,7,8,9,10};
vector<int> v1(t, t+10);
vector<int> v2(10);
transform(v1.begin(), v1.end(), v2.begin(), bind1st(1,Add()));
for_each(v2.rbegin(), v2.rend(), Out<int>(cout));cout<<endl;
return 0;
}
Program outputs:
A. compilation error
B. 1 2 3 4 5 6 7 8 9 10
C. 11 10 9 8 7 6 5 4 3 2
D. 10 9 8 7 6 5 4 3 2 1
E. 2 3 4 5 6 7 8 9 10 11
Answer: A
CPP Torrent
NO.2 What happens when you attempt to compile and run the following code?
#include <list>
#include <iostream>
using namespace std;
template<class T> void print(T start, T end) {
while (start != end) {
std::cout << *start << " "; start++;
}
}
class A {
int a;
public:
A(int a):a(a){}
operator int () const { return a;}int getA() const { return a;}
};
int main() {
int t1[] ={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
list<A> l1(t1, t1 + 10);
list<A> l2(l1);
l2.reverse(); l1.splice(l1.end(),l2);
l1.pop_back();l1.unique();
print(l1.begin(), l1.end()); cout<<endl;
return 0;
}
A. compilation error
B. program outputs: 1 2 3 4 5 6 7 8 9 10 10 9 8 7 6 5 4 3 2
C. runtime exception
D. program outputs: 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2
E. program outputs: 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1
Answer: D
CPP Blueprint
Buying any product should choose a trustworthy company. Our BraindumpStudy can give you the promise of the highest pass rate of CPP Valid Braindumps Book exam; we can give you a promise to try our CPP Valid Braindumps Book software for free, and the promise of free updates within a year after purchase. To resolve your doubts, we assure you that if you regrettably fail the CPP Valid Braindumps Book exam, we will full refund all the cost you buy our study materials. BraindumpStudy is your best partners in your preparation for CPP Valid Braindumps Book exam.
Exam Name: C++ Certified Professional Programmer
One year free update, No help, Full refund!
CPP Valid Braindumps Book Total Q&A: 230 Questions and Answers
Last Update: 2017-03-30
New CPP Exam Questions Detail: CPP Valid Braindumps Book
It is no longer an accident for you to pass CPP Valid Braindumps Book exam after you have use our CPP Valid Braindumps Book exam software. You will have thorough training and exercises from our huge question dumps, and master every question from the detailed answer analysis. The exam software with such guarantees will clear your worries about CPP Valid Braindumps Book exam.
CPP Free Demo Download: http://www.braindumpstudy.com/CPP_braindumps.html
没有评论:
发表评论