Ok, so I've successfully written my swap application but now i'm trying to rewrite it so i'm using pointers to pass the address of the argument to the function. I'm going to have the swapping performed in the main function after calling the swap function.
Code:
#include <iostream.h> void main() { void swap(int x, int y); int first_num = 10; int second_num = 50; cout << "\nThe value of first_num is " << first_num << endl << "The value of second_num is " << second_num << endl; swap(first_num, second_num); cout << "\nThe value of first_num is now " << first_num << endl << "The value of second_num is now " << second_num << endl; } void swap(int x, int y) { int local_int; local_int = x; x = y; y = local_int; cout << "\nIn the function first_num is " << x << endl << "In the function second_num is " << y << endl; }
Comment