Aspire's Library

A Place for Latest Exam wise Questions, Videos, Previous Year Papers,
Study Stuff for MCA Examinations - NIMCET

Previous Year Question (PYQs)



#include<iostream.h>
using namespace std;

void swap(int &x, int &y)
{
    int temp = x;
    x = y;
    y = temp;
}

int main()
{
    int a = 5, b = 10;
    swap(a,b);
    swap(a,b);
    cout << a << " " << b;
    return 0;
}
What will be the output of above code ?





Solution

Initial values

$a = 5,; b = 10$

First call

swap(a,b)

$a = 10,; b = 5$

Second call

swap(a,b)

$a = 5,; b = 10$

Thus final output

5 10



Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More


Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More

Ask Your Question or Put Your Review.

loading...