Swapping by Call by Reference or Pointer using C++
This is a simple programming tutorial for swapping values of the two variables by passing parameters to a function using call by reference or call by pointer method in C++. The reference variables are represented by an ampersand symbol ( & ) before the variable name, and pointer variables are represented by an asterisk symbol ( * ) before the variable name. In this tutorial, I have used Turbo C++ v3.0 and GNU GCC v7.1.1 software for compiling the C++ program. The values of the two variables can be swapped by initially assigning the value of a variable to a temporary variable in a cyclic order. For instance, a = 1 and b = 2 , then t = a , a = b , and b = t . Swapping by Call by Reference The call by reference method of passing arguments to a function copies the reference of an argument into the formal parameter. Inside the function, the reference is used to access the actual argument used in the call. This means that changes made to the parameter affect the passed argume...