#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;
}
#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 the above code?
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: A. 5, 10
Explanation
swap takes references, so the first call makes a = 10, b = 5 and the second swaps them back. Output: 5 10.
More Programming Languages and Computer Graphics questions
- Arrange the following steps of file handling in C in the correct order : (A) Close the file (B) Read from or write to the file (C) Open the…
- #include<stdio.h> void main() { int arr[ ] = {1, 2, 3, 4, 5}; int *p = arr; printf("%d", *p++); printf("%d", *(p+1)); } Find the output of…
- Which of the following is not an object Oriented Programming language ?
- Multiple Inheritance is permitted directly in..... A. C++ B. Java C. Python D. VB.NET E. BASIC
- Match List-I with List-II :
- For line drawing, which of the following algorithms are used ? A. DDA algorithm B. Bresenham algorithm C. Mid point algorithm D. Curve algo…