陣列做函式引數的退化問題
阿新 • • 發佈:2018-12-31
氣泡排序
#include "stdlib.h" #include "string.h" #include "stdio.h" void printArray(int* a) { for (size_t i = 0; i < 6; i++) { printf("%d\n", a[i]); } } // -----------(int a[]) void sortAarry(int* a) { int tem = 0; for (size_t i = 0; i < 6; i++) { for (size_t j = i + 1; j < 6; j++) { if (a[i] < a[j]) { tem = a[i]; a[i] = a[j]; a[j] = tem; } } } } void main() { int i = 0; int a[] = { 22, 56, 4, 57, 8, 10 }; printf("----before-----\n"); printArray(a); //排序 //外層內層 sortAarry(a); printf("----after-----\n"); printArray(a); }