Preview
Structure type arguments in C
Two methods to pass structure type arguments are:
- Pass structure elements as arguments independently.
- Pass structure variable as argument.
To pass structure elements as argument independently
Program |
#include<stdio.h> struct emp { int empid; float sal; };void show(int i,float s) { printf(“\n%d,%f”,i,s); } int main() { struct emp e1={101,5500.00}; show(e1.empid,e1.sal); return(0); } |
Output |
131,550.500000 |
Pass structure variable as argument
In this case structure variable is passed as an actual argument to a function
Program |
#include<stdio.h> struct demo { int x,y; }; void disp(struct demo d1) { ++d1.x; – -d1.y;printf(“\nd1.x=%d”,d1.x); printf(“\nd1.y=%d”,d1.y); } int main() { struct demo d={10,15}; |
Output |
d1.x=11 d1.y=14 |
Best Sellers