数组做为函数的参数,他吗的,越日后越很差理解,都没地方发牢骚,哎
数组
#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