鱼C论坛

 找回密码
 立即注册
查看: 1231|回复: 4

[已解决]有大佬吗,结构体变量有的地方没看懂

[复制链接]
发表于 2019-10-10 00:20:15 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include<stdio.h>
# define N 3
struct student
{
        int num;
        char name[20];
        float score[3];
        float aver;
} ;
int main()
{
        void input (struct student str[]);                                                                                                                                //这里str[]是个数组吗?如果是为什么不用个下标赋值就能运行
        struct student max(struct student str[]);
        struct student str[N],*p=str;
        input(p);
        print(max(p));
        return 0;
}
void input (struct student str[])
{
        int i;
        printf("请输入各类学生的信息;学号、姓名、3门课程;\n");
        for(i=0;i<N;i++)
        {
                scanf("%d%s%f%f%f",&str[i].num,&str[i].name,&str[i].score[0],&str[i].score[1],&str[i].score[2]);
                str[i].aver=(str[i].score[0]+str[i].score[1]+str[i].score[2])/3;
         }
       
}
struct student max(struct student str[])
{
        int i,m=0;
        for(i=0;i<N;i++)
        {
                if(str[i].aver>str[m].aver)m=i;
         }
         return (str[m]);
}
void print(struct student str)
{
        printf("\n成绩最高的学生是\n");
        printf("学号%d\n姓名%s\n三门课成绩%5.1f,%5.1f,%5.1f\n平均成绩%6.2f\n",
         str.num,str.name,str.score[0],str.score[1],str.score[2],str.aver);
}
最佳答案
2019-10-10 00:31:49
# define N 3
struct student
{
        int num;
        char name[20];
        float score[3];
        float aver;
} ;
int main()
{
. . . . . .   
        struct student str[N],*p=str;
. . . . . .
}
void input (struct student str[])

      很显然,str 是 1 个拥有 3 个 struct student 结构体类型元素的一维数组。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2019-10-10 00:21:01 | 显示全部楼层
就注释哪里没看懂
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-10-10 00:31:49 | 显示全部楼层    本楼为最佳答案   
# define N 3
struct student
{
        int num;
        char name[20];
        float score[3];
        float aver;
} ;
int main()
{
. . . . . .   
        struct student str[N],*p=str;
. . . . . .
}
void input (struct student str[])

      很显然,str 是 1 个拥有 3 个 struct student 结构体类型元素的一维数组。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-10-10 10:26:19 From FishC Mobile | 显示全部楼层
jackz007 发表于 2019-10-10 00:31
# define N 3
struct student
{

意思是在函数声明里系统是把他看做指针吗?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-10-10 10:34:40 From FishC Mobile | 显示全部楼层
    一维数组自然等同于结构体指针了。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-23 14:08

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表