#include void print_array( int [], int ); void swap_by_value( int, int ); void swap_by_reference( int [], int, int ); int main() { int a, b, x, y; int size = 6; int list[] = { 0, 1, 2, 3, 4, 5 }; a = 2; b = 4; printf( "\n" ); printf( "Before calling swap_by_reference...\n" ); print_array( list, size ); swap_by_reference( list, a, b ); printf( "\n" ); printf( "After calling swap_by_reference...\n" ); print_array( list, size ); printf( "\n" ); x = 10; y = 5; printf( "Before swap_by_value in main: \n" ); printf( " x = %d\n", x ); printf( " y = %d\n", y ); printf( "\n" ); swap_by_value( x, y ); printf( "\n" ); printf( "After swap_by_value in main: \n" ); printf( " x = %d\n", x ); printf( " y = %d\n", y ); printf( "\n" ); return 0; } void print_array( int list[], int num_list ) { int list_i; for ( list_i = 0; list_i < num_list; list_i++ ) { printf( " - list[%d]: %d\n", list_i, list[ list_i ] ); } printf( "\n" ); return; } void swap_by_reference( int reference[], int index_1, int index_2 ) { int temp; printf( "Start of swap_by_reference...\n" ); printf( " reference[%d]: %d\n", index_1, reference[ index_1 ] ); printf( " reference[%d]: %d\n", index_2, reference[ index_2 ] ); temp = reference[ index_1 ]; reference[ index_1 ] = reference[ index_2 ]; reference[ index_2 ] = temp; printf( "End of swap_by_reference...\n" ); printf( " reference[%d]: %d\n", index_1, reference[ index_1 ] ); printf( " reference[%d]: %d\n", index_2, reference[ index_2 ] ); return; } void swap_by_value( int value_1, int value_2 ) { int temp; printf( " Start of swap_by_value...\n" ); printf( " value_1 = %d\n", value_1 ); printf( " value_2 = %d\n", value_2 ); temp = value_1; value_1 = value_2; value_2 = temp; printf( " End of swap_by_value...\n" ); printf( " value_1 = %d\n", value_1 ); printf( " value_2 = %d\n", value_2 ); return; }