指针
- 指针:记录变量或对象的内存存储位置
- 缺陷:C 使用数组一般使用数组指针形式,并且显示指定数组长度,但是无法处理动态数组的长度参数指定问题
测试代码
#include <stdio.h>
#include<ctype.h>
typedef struct Student{
char num[10];
int score;
}Stu;
int fun(Stu *s){
int length=0;
while(true){
Stu p=*(s+length); //移动指针取值:
//判断空地址的取值是否为字母从而得出数组长度判断的临界值
if(!isalpha(p.num[0]))
break;
length++;
}
return length;
}
int main(){
Stu students[4]={"zhangsan",88,"lisi",60,"wangwu",90,"maliu",75};
int length=fun(students);
printf("数组长度:%d",length);
}
缺陷
该方法对数组的成员对象类型具有约束,不能作为获取数组长度的通用接口