如何返回struct变量并在函数之间传递?

时间:2018-04-19 22:50:51

标签: c struct

我在使用struct变量时遇到了麻烦,尝试编写,传递和显示。如何返回结构变量并在函数之间传递它们? 感谢

#include <stdio.h>
struct student 
{
    int math;
    int science;
    int english;
};

int func(struct student record);
int printresult(struct student record); 

int main(void) 
{
    struct student record;
    func(record);
    printresult(record);
    return 0;
}
int func(struct student record)
{
    printf("Enter marks for math, english and science:");
    scanf("%d %d %d", &record.math, &record.science, &record.english);
    return record;
}
int printresult(struct student record) 
{
    printf(" Math mark is: %d \n", record.math);
    printf(" Science mark is: %d \n", record.science);
    printf(" English mark is: %d \n", record.english);
    return 0 ;
}

0 个答案:

没有答案
相关问题