Sail E0 Webinar
Question


What is the output of this program?


1.
#include
2.
using namespace std;
3.
void swap(int &a, int &b);
4.
int main()
5.
{
6.
int a = 5, b = 10;
7.
swap(a, b);
8.
cout
Options:
A .  In swap 105 In main 105
B .  In swap 105 In main 510
C .  In swap 510 In main 105
D .  none of the mentioned
Answer: Option A

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

values also changed.
Output:
$ g++ ref.cpp
$ a.out
In swap 105 In main 105



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers