Call by address in C++ with example

Calling a function by passing the address of an actual argument is called by address.

C++ Program to call by address function

#include<iostream> using namespace std; void swap(int *a, int *b){ int z; z = *a; *a = *b; *b = z; } int main(){ int a = 31, b = 32; cout<<"Before :"<<a<<","<<b<<endl; swap(&a,&b); cout<<"After :"<<a<<","<<b; return 0; }


Before :31,32
After :32,31

Explanation of the program

Here, the address of the arguments is passed on to the function and not the value of the variables.