- Passing structure to function program in C
#include<stdio.h> #include<conio.h> struct student { char name[20]; int roll; char clas[10]; char college[20]; }; void Show(struct student ); int main() { struct student s1={"Pankaj kumar ",11,"BCA","R.D.S.college"}; Show(s1); } void Show(struct student stu) { printf("Name of student :-%s",stu.name); printf("\nRoll No.:-%d",stu.roll); printf("\nClass :-%s",stu.clas); printf("\nCollege name:-%s",stu.college); }Output:-
- Passing structure to function
Created input and Show user define function in this below program input function for input details and Show function for display input details entered by the user
#include<stdio.h> #include<conio.h> struct student { char name[20]; int roll; char clas[10]; char college[20]; }; struct student input(struct student); void Show(struct student ); int main() { struct student std,std1; std1=input(std); printf("\n\nEntered information is \n"); Show(std1); } struct student input(struct student s1) { printf("Enter name:-"); gets(s1.name); printf("Roll No.:-"); scanf("%d",&s1.roll); fflush(stdin); printf("Class :-"); gets(s1.clas); printf("College name:-"); gets(s1.college); return(s1); } void Show(struct student stu) { printf("Name of student :-%s",stu.name); printf("\nRoll No.:-%d",stu.roll); printf("\nClass :-%s",stu.clas); printf("\nCollege name:-%s",stu.college); }Output:-
0 Comments