Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute Exam CPP Topic 5 Question 83 Discussion

Actual exam question for C++ Institute's CPP exam
Question #: 83
Topic #: 5
[All CPP Questions]

What happens when you attempt to compile and run the following code?

#include

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

Out(ostream & o): out(o){}

void operator() (const T & val ) { out<

int main() {

int t1[]={1,2,3,4,5,6,7,8,9,10};

int t2[]={1,2,3,4,5,6,7,8,9,10};

vector v1(t1, t1+10);

vector v2(t2, t2+10);

vector v3(10);

transform(v1.begin(), v1.end(), v2.rbegin(), v3.begin(), minus());

for_each(v3.rbegin(), v3.rend(), Out(cout));cout<

return 0;

}

Program outputs:

Show Suggested Answer Hide Answer
Suggested Answer: C

Contribute your Thoughts:

Jolanda
21 hours ago
Whoa, this is some serious C++ STL magic! I'm still trying to wrap my head around all the template shenanigans and functor business. But I think I got it - the transform() function is subtracting the elements of v2 in reverse order from the corresponding elements in v1, and the for_each() loop is printing the results in reverse order. The correct answer is C) 1 0.
upvoted 0 times
...
Rene
5 days ago
The code is doing a bit-by-bit subtraction of the elements of the two input vectors, v1 and v2, and storing the results in v3. Since the elements of v2 are being accessed in reverse order, the output will be the differences between the corresponding elements in the two vectors.
upvoted 0 times
...
Rodrigo
8 days ago
Why do you think it's C)?
upvoted 0 times
...
Katlyn
10 days ago
I disagree, I believe the correct answer is C) 1 0.
upvoted 0 times
...
Rodrigo
15 days ago
I think the answer is B) 0 1.
upvoted 0 times
...
Alva
17 days ago
Hmm, the transform() function is taking the elements of v1 and v2 in reverse order and subtracting them, storing the results in v3. The for_each() loop is then printing the elements of v3 in reverse order. I think the correct answer is C) 1 0.
upvoted 0 times
...
Dianne
18 days ago
This code looks like it's using the transform() and for_each() algorithms to perform some kind of vector manipulation. The output suggests that the transform() is subtracting the elements of the two input vectors, but I'm not sure about the details.
upvoted 0 times
Kenny
4 days ago
User 1
upvoted 0 times
...
...

Save Cancel
az-700  pass4success  az-104  200-301  200-201  cissp  350-401  350-201  350-501  350-601  350-801  350-901  az-720  az-305  pl-300  

Warning: Cannot modify header information - headers already sent by (output started at /pass.php:70) in /pass.php on line 77