Example 1: Swapping integers. swap1(a,b) : call by value swap2(a,b) : call by reference. swap2(a,b,c,d) : call by reference. swap2 is overloaded. #include using namespace std; void swap1(int a, int b){ int temp = a; a = b; b = temp;; return; } void swap2(int& a, int& b){ int temp = a; a = b; b = temp; return; } void swap2(int& a, int& b, int& c, int& d) { swap2(a,b); swap2(c,d); return; } int main() { int num1, num2, num3, num4; cin >> num1 >> num2 >> num3 >> num4; swap1(num1, num2); cout << num1 << " " << num2 << "\n"; // line A swap2(num1, num2); cout << num1 << " " << num2 << "\n"; // line B swap2(num1,num2, num3,num4); cout << num3 << " " << num4 << "\n"; // line C return 0; } Example 2 : Sorting integers. This program sorts the integers in decreasing order. This algorithm is known as "selection sort". #include using namespace std; void swap(int& a, int& b) { int temp; temp = a; a = b; b = temp; return; } int find_max_index(int arr[], int low, int high) { int m, index, c; m=arr[low]; index=low; for(c=low + 1; c <= high; c++) { if (arr[c] > m) { m = arr[c]; index = c; } } return index; } int main() { int a[10]; int b,c; for(b=0;b<10;b++) { cin >> a[b]; } for(b=0;b<9;b++){ c = find_max_index(a,b,9); swap(a[b],a[c]); } for(b=0;b<10;b++) cout << a[b] << " "; cout << endl; return 0; }