Passing Structure to Function in C Programming
- Structure can be passed to function as a Parameter.
- function can also Structure as return type.
- Structure can be passed as follow
#include<stdio.h> #include<conio.h> //------------------------------------- struct Example { int num1; int num2; }s[3]; //------------------------------------- void accept(struct Example *sptr) { printf("\nEnter num1 : "); scanf("%d",&sptr->num1); printf("\nEnter num2 : "); scanf("%d",&sptr->num2); } //------------------------------------- void print(struct Example *sptr) { printf("\nNum1 : %d",sptr->num1); printf("\nNum2 : %d",sptr->num2); } //------------------------------------- void main() { int i; clrscr(); for(i=0;i<3;i++) accept(&s[i]); for(i=0;i<3;i++) print(&s[i]); getch(); }
Enter num1 : 10 Enter num2 : 20 Enter num1 : 30 Enter num2 : 40 Enter num1 : 50 Enter num2 : 60 Num1 : 10 Num2 : 20 Num1 : 30 Num2 : 40 Num1 : 50 Num2 : 60

0 Comments:
Post a Comment
Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email