Questions and Answers


  1. What is the output of this program?
    #include <iostream>
    #include <stack>
    using namespace std;
    int main ()
    {
    stack<int> StackData;
    StackData.push(25);
    StackData.push(45);
    StackData.top() -= 5;
    cout << StackData.top() << endl;
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    In this program, We used top option and this will return the reference to the next element.


  1. What is the output of this program?
     #include <iostream>
    #include <string>
    #include <bitset>
    using namespace std;
    int main ()
    {
    string Str;
    bitset<5> BitsetData;
    BitsetData.set();
    Str = BitsetData.to_string<char, char_traits<char>,
    allocator<char> >();
    cout << Str ;
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    In this program, We converted the bitset values to string and printing it.



  1. How many items are presented in the associate container?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    There are 4 items presented in the associate container. They are set, multiset, map and multimap.


  1. By using which of the following the elements in the associate container can be efficiently accessed?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    Associative containers are designed to be especially efficient in accessing its elements by their key, as opposed to sequence containers which are more efficient in accessing elements by their position.



  1. What is the output of this program?
    #include <iostream>
    #include <algorithm>
    #include <vector>
    using namespace std;
    int main ()
    {
    vector<int> firstRow (4, 15);
    vector<int> secondRow (4, 26);
    vector<int>::iterator iter;
    swap_ranges(firstRow.begin() + 1, firstRow.end() - 1, secondRow.begin());
    cout << "First Row contains:";
    for (iter = firstRow.begin(); iter != firstRow.end(); ++iter)
    cout << " " << *it;
    cout << "\nSecond Row contains:";
    for (it = secondRow.begin(); it != secondRow.end(); ++it)
    cout << " " << *it;
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    In this program, We swapped the values according to their position.