Examveda

What will be the output of the following C++ code?
#include <iostream>
#include <deque>
using namespace std;
int main ()
{
    unsigned int i;
    deque<int> a (3,100);
    deque<int> b (5,200);
    a.swap(b);
    cout << "a contains:";
    for (deque<int>::iterator it = a.begin(); it != a.end(); ++it)
        cout << ' ' << *it;
    cout << "b contains:";
    for (deque<int>::iterator it = b.begin(); it != b.end(); ++it)
        cout << ' ' << *it;
    return 0;
}

A. a contains: 200 200 200 200 200b contains: 100 100 100

B. a contains: 100 100 100 100 100b contains: 200 200 200

C. a contains: 200 200 200 200 200b contains: 200 200 200

D. a contains: 200 200 200 200 200b contains: 100 200 150

Answer: Option A


Join The Discussion

Related Questions on C plus plus miscellaneous

What is the difference between '++i' and 'i++' in C++?

A. None of the above

B. They both have the same effect

C. '++i' increments the value of 'i' before returning it, while 'i++' increments the value of 'i' after returning it

D. '++i' increments the value of 'i' after returning it, while 'i++' increments the value of 'i' before returning it