DSA 1.15 : Parameter passing method- by address

PHOTO EMBED

Tue Mar 07 2023 08:04:03 GMT+0000 (Coordinated Universal Time)

Saved by @saakshi #c++

#include <iostream>
using namespace std;
 
void swap(int *x, int *y)        //getting the pointers 
{
  int temp;
  temp = *x;
  *x=*y;
  *y = temp;
}
int main()
{
  int a, b;
  a=10;
  b=20;
  swap(&a,&b);          //passing the address
  
  cout << "a = "<<a <<", b = "<<b << endl;     //a = 10, b = 20
  
  return 0;
}
content_copyCOPY

parameter passing by address