數組做爲函數的參數,他嗎的,越日後越很差理解,都沒地方發牢騷,哎
數組
#include <stdio.h> #define world 5 void hello(int []); int main(void) { int i; n[world] = {1,2,3,4,5}; hello(n); for(i = 0;i < world;i++) { printf("%d",n[i]); } printf("\n"); return 0; } void hello(int t[]) { int i; for(i = 0;i < world;i++) // { t[i] = i + 5; // printf("%d",t[i]); // } // printf("\n"); } /* 能夠看出,定義區和功能區的數組名稱能夠不一樣,可是像上面的這種狀況必需要名稱一致 */ /* 上面的循環要麼定義去直接循環好,要麼兩處都需循環 */ 再寫個指針做爲函數的參數,以下: #include <stdio.h> void hello(int *); int main(void) { int i = 50; hello(&i); printf("%d\n",i); return 0; } void hello(int *n) { *n = 10; } //運行的結果是10