
将各个成员作为参数传递给函数 -
每个成员都作为函数调用中的参数传递。
它们在函数头中的普通变量中独立收集。
#include<stdio.h>
//Declaring structure//
struct student{
int s1,s2,s3;
}s[5];
//Declaring and returning Function//
void addition(int a,int b,int c){
//Declaring sum variable and For loop variable//
int i,sum;
//Arithmetic Operation//
for(i=1;i<4;i++){
sum=a+b+c;
printf("Student %d scored total of %d</p><p>",i,sum);
}
}
void main(){
//Declaring variable for For loop//
int i;
//Reading User I/p through For loop//
for(i=1;i<4;i++){
printf("Enter marks for student %d in subject 1 = ",i);
scanf("%d",&s[i].s1);
printf("Enter marks for student %d in subject 2 = ",i);
scanf("%d",&s[i].s2);
printf("Enter marks for student %d in subject 3 = ",i);
scanf("%d",&s[i].s3);
}
//Calling function//
addition(s[].s1,s[].s2,s[].s3);
}day = 2 month = 1 year = 2010
以上就是如何在C语言中将结构体的各个成员作为参数传递给函数?的详细内容,更多请关注php中文网其它相关文章!
C语言怎么学习?C语言怎么入门?C语言在哪学?C语言怎么学才快?不用担心,这里为大家提供了C语言速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号