Function returning structure:
- A function can return the structure type.
- We need to specify the structure type as return type.
- It returns the base address of structure memory block.
- We collect the returned address into same type of structure variable in the calling function.
- The program as follows:
#include<stdio.h>
struct Emp
{
int no;
char name[20];
float salary;
};
struct Emp read();
int main()
{
struct Emp y;
y = read();
printf("Name : %s\n", y.name);
return 0;
}
struct Emp read()
{
struct Emp x;
printf("Enter Emp details : \n");
scanf("%d%s%f", &x.no, x.name, &x.salary);
return x;
}