#include<stdio.h>
#define n 2 //宏定义 ,当需要改变这个常量的值时,就不需要对整个程序一个一个进行修改,只需修改宏定义中的常量即可
//预处理就是“文本替换”
struct student3 //定义结构体
{
long num;
char name[20];
int age;
};
//struct student3 s[n];
void h(struct student3 s[n]) //定义函数获取用户输入的值 参数是结构体变量
//作为函数形参时(也只有这种情况),数组与指针等同,int *p = int a[],p和a在函数内部都是指针,所以定不定义长度都一样
//struct student3 不能丢!!
{
int i;
for ( i = 0; i < n; i++)
{
scanf("%ld",&s[i].num);
scanf("%s",s[i].name);
scanf("%d",&s[i].age);
}
return;
}
main()
{
struct student3 t[n];
int i;
h(t); //传入一个实参
for ( i = 0; i < n; i++)
{
printf("\n%ld%s%d\n",t[i].num,t[i].name,t[i].age);
}
}
结构体数组
最新推荐文章于 2024-07-11 23:55:49 发布