Declaration of structure:-
struct structure_name
{
data_type member 1;
data_type member 2;
.
.
.
data_type member n;
} structure variable 1, structure variable 2,..., structure variable n;
Example:-
struct student
{
int rollno;
char name[10];
}s1;
Initialization:-
struct student s={1,"abc"};
structure variable contains two members as rollno and name. the above example initializes rollno to 1 and name to "abc".
Program:-
#include<stdio.h>
#include<conio.h>
struct college
{
int collegeid;
char collegename[20];
};
struct student
{
int rollno;
char studentname[10];
struct college c;
};
void main()
{
struct student s={1,"ABC",123,"Polytechnic"};
clrscr();
printf("\n Roll number=%d",s.rollno);
printf("\n Student Name=%s",s.studentname);
printf("\n College id=%d",s.c.collegeid);
printf("\n College name=%s",s.c.collegename);
getch();
}