//数组做函数参数不传数组个数的遍历方法 #include<stdio.h> #include<stdlib.h> #include<string.h> void PrintfAK(char **pin){ int i = 0; //关键点:pin[i]!=NULL为终止条件 for (i = 0; pin[i]!=NULL; i++) { printf("%s\n", pin[i]); } } void main(){ //赋值数组最后一个元素是0 //经过实际检测 NULL,0,‘\0‘的意义一样 都是00000 char * strarr1[] = {"123","456","789",NULL}; char * strarr2[] = { "123", "456", "789", ‘\0‘ }; char * strarr3[] = { "123", "456", "789", 0 }; printf("%x\n", strarr1); printf("%x\n", strarr2); printf("%x\n", strarr3); //一种新的数组遍历办法,不用传数组元素个数 PrintfAK(strarr1); system("pause"); }
时间: 2024-10-05 04:43:22