Function returning structure type data in C Language

Function returning structure type data in C Language

We can make return type of any function to be a structure. The very main thing to be noted in this case is that the function must be returning the variable of structure type.

Program to specify a structure as the return type of function.

#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

Spread the love
Lesson tags: Function returning structure in C Language, function returning structure type data, return structure type data, structure as function return type
Back to: C Programming Language
Spread the love