Thursday, May 21, 2020

Pass By Reference using functions in C++


  • Program :

#include <iostream>
using namespace std;
void swapNums(int &x, int &y)
{
  int z = x;
  x = y;
  y = z;
}


int main(){
  cout <<"\n----------------FUNCTION PARAMETERS----------------\n";
  cout <<"\n----------------Pass By Reference----------------\n";
  int a = 10, b = 5;
  cout << "Before swap: " << "\n";
  cout << a <<" and "<< b << "\n";

  swapNums(a, b);

  cout << "After swap: " << "\n";
  cout << a <<" and "<< b << "\n";

  return 0;
}




  • Output :


No comments:

Post a Comment

Function Overloading in C++

https://monitechvenkat1620.blogspot.com Program : #include <iostream> using namespace std; int c(int x, int y) {   return...