Function returning structure in C

Preview

Function returning structure in C

Return type of any function can be a structure but the function must return the variable of structure type.

Program
#include<stdio.h>
struct data
{
int a,b;
};struct data show(struct data d)
{
++d.a;
–d.b;
return(d);
}
int main()
{struct data d1={34,55};
struct data s;
s=show(d1);
printf(“\ns.a=%d”,s.a);
printf(“\ns.b=%d”,s.b);
return(0);
}
Output
s.a=35
s.b=54

Best Sellers





Lesson tags: function returning structure type data, return structure type data, structure as function return type
Back to: C Programming Language