Pointer as function parameter, pointer function parameter
Demonstration Result 1:
Demonstration Result 2:
Sample Code:
# Include <iostream> void swap (int *, int *); void swap1 (int *, int *); void function1 (void); void displayIntArray (int *, int ); void bubbleSort (int *, int); void function2 (void); int main (int argc, char ** argv) {// function1 (); function2 (); return 0;}/** demonstrate sorting */void function2 (void) {int array [10] = {9, 1 }; printf ("original array:"); displayIntArray (array, 10); bubbleSort (array, 10); printf ("sorted array:"); disp LayIntArray (array, 10);}/** bubble sort */void bubbleSort (int * array, int arrayLength) {for (int I = 0; I <arrayLength; I ++) {for (int j = 1; j <arrayLength-I; j ++) {if (array [j] <array [J-1]) {swap1 (& array [j], & array [J-1]) ;}}}/** display array */void displayIntArray (int * a, int arrayLength) {for (int I = 0; I <arrayLength; I ++) {printf ("% d", a [I]); /* change a row of five numbers if (I + 1) % 5 = 0) {printf ("\ n ");} */} printf ("\ n");}/** demo transposition */ Void function1 (void) {int a = 0 xffffffff; int B = 0 xfffffe; printf ("a = % d, B = % d \ n", a, B ); swap1 (& a, & B); printf ("a = % d, B = % d \ n", a, B); int c = 0x7fffffff; int d = 0x00000001; printf ("c = % d, d = % d \ n", c, d); swap1 (& c, & d ); printf ("c = % d, d = % d \ n", c, d);}/** switching algorithm 1 */void swap (int *, int * B) {int temp = * a; * a = * B; * B = temp;}/** switching algorithm 2 */void swap1 (int *, int * B) {// the sum of the two numbers must be greater than 0 xffffffff. * A = * a + * B; // 10 9 * B = * a-* B; // 10 1 * a = * a-* B ;}