-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcallbyreference.cpp
More file actions
42 lines (33 loc) · 877 Bytes
/
callbyreference.cpp
File metadata and controls
42 lines (33 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<iostream>
using namespace std;
void swap(int &x,int &y) //formal parameters
{
int temp;
temp = x;
x = y;
y = temp;
cout<<"During swap\t"<<x<<"\t"<<y<<endl;
}
int main()
{
int a,b;
cout<<"Enter the values for a and b ";
cin>>a>>b;
cout<<"before swap\t"<<a<<"\t"<<b<<endl;
swap(a,b); //actual parameters
cout<<"after swap\t"<<a<<"\t"<<b<<endl<<endl;
cout<<&a; //address of will be shown
return 0;
}
/*
& - address of
while reference of the variable is passed the changes are made
at the memory location of the variables.
*/
/********************************************************
Title: Function with call by reference arguments.
Author: CAC
Date: 5th April 2021
Description:
This code was implemented on day 8 of 100 days of code
*********************************************************/