C Language



Admission Enquiry Form

  

Nested Structure in C


What is Nested Structure in C?

Nested structure means structure within structure.In nested structure we can declare one structure inside another structure like other data members of the nesting structure.

Example:

#include<stdio.h>
struct date
{
int day;
int month;
int year;
};
struct student
{
int rollno;
float fee;
char name[10];
struct date doj;
};
void main()
{
struct student st;
printf("Enter rollno ");
scanf("%d",&st.rollno);
printf("Enter fee ");
scanf("%f",&st.fee);
printf("Enter name ");
scanf("%s",&st.name);
printf("Enter day ");
scanf("%d",&st.doj.day);
printf("Enter month ");
scanf("%d",&st.doj.month);
printf("Enter year ");
scanf("%d",&st.doj.year);

printf("\nRollno is %d",st.rollno);
printf("\nFee is %f",st.fee);
printf("\nName is %s",st.name);
}


Output

Enter rollno 10
Enter fee 15000
Enter name sunil
Enter day 20
Enter month 7
Enter year 2020

Rollno is 10
Fee is 15000.000000
Name is sunil
Date of joining is : 20-7-2020