Nesting of Structure in C Language | Program of nesting of structure in C Language

Nesting of Structure in C Language | Program of nesting of structure in C Language

Defining one structure within another structure is known as  nesting of structure. We can do it as follows:

Program of nesting of structure in C Language.

#include<string.h>
#include<stdio.h>
struct dob
{
  int dd;
  int mm;
  int yy;
};
struct std
{
  int roll;
  char sname[20];
  struct dob d1;
};
int main()
{
  struct std s1;
  s1.roll=131;
  strcpy(s1.sname,"Aman");
  s1.d1.dd=23;
  s1.d1.mm=3;
  s1.d1.yy=2022;
  printf("\nroll=%d",s1.rollo);
  printf("\nsname=%s",s1.name);
  printf("\nDate=%d/%d/%d",s1.d1.dd,s.d1.mm,s1.d1.yy);
  return(0);
}

Output

Rollno=131
Name=Lovejot
Date of Birth=11/7/2007

In the above program, variable d of structure dob has been declared inside the structure student

Spread the love
Lesson tags: nesting of structure in c, Nesting of Structure in C Language, program of nesting of structure in c, structure nesting in c, take a nested structure variable in c
Back to: C Programming Language
Spread the love