Home » C++ Programming » References » Question
  1. What is the output of this program?
    #include 
    using namespace std;
    void swap(int &p, int &q);
    int main()
    {
    int p = 5, q = 10;
    swap(p, q);
    cout << " In main " << p << q;
    return 0;
    }
    void swap(int &p, int &q)
    {
    int temp;
    temp = p;
    p = q;
    q = temp;
    cout << "In swap " << p << q;
    }
    1. In swap 11 15
    2. In main 11 15
    3. Compilation Error
    4. Runtime Error
    5. In swap 11 15 In main 11 15
Correct Option: E

As we are calling by reference the values in the address also changed. So the main and swap values also changed.



Your comments will be displayed only after manual approval.