Structure:-


A structure is a bundle of different variables eac h of different type ,we use these structure to def ine a very new user defined data type. the variables bundeled within the structure are ca lled members of that structures .further we can us e this new data type to declare variables in an ma in() body. the size of variables of structure type will be eq ual to the total size of the member in that struct ure.

declaration of a structure-:

structure employee structure name
{
char e_name[30];
int e_id,e_sub
};
different types to initialize a structure-:


via assignment
void main()
{
typedef struct employee emp;
emp e1,e2;
e1.e_name="abc";
e1.e_id="abc";
e1.e_salary="6000";
via scanf()


void main()
{
typedef struct employee emp;
emp e1,e2;
printf("enter employee name ,id and salary");
scanf("%s%d%d",e1.e_name,e1.e_id,e1.e_salary);
____________________
____________________
____________________
____________________
}


program to introduce structure-:
#include< stdio.h>
#include< conio.h>
struct student
{
int st_roll;
float st_marks;
char st_name;
};
void main()
{
typedef struct student std;
std s1,s2;
clrscr();
printf("enter roll number name and marks of student ");
scanf("%s%d%f",s1.st_name,&s1.st_roll,&s1.st_marks) ;
printf("you entered ");
printf("name=%sroll number%dmarks%f",s1.st_name,&s1 .st_roll,&s1.st_marks");
getch();
}



handling of float in array of structure-:

#include< stdio.h>
#include< conio.h>
struct book
{
int bid,bnop;
float bprice;
char st_name;
};
void main()
{
typedef struct book bk;
bk b[2];
int i;
for(i=0;i<2;i++)
{
printf("enter id,no of pages and price of book %d", i+1);
scanf("%d%d%f",&b[i].bid&b[i].bnop&b[i].bprice);
}
void link()
{
float a,*p;
p=&a;
a=*p;
}



accessing structure via pointer-:


#include< stdio.h>
#include< conio.h>
struct book
{
int stroll;
float stmarks;
char stname[30];
};
void main()
{
typedef struct student std;
std f1,*p1;
p1=&f1;
clrscr();
printf("enter name roll number name and marks of st udent");
fflush(stdin);
scanf("%s\n"p1->stname);
scanf("%d\n%f",&p1->stroll,&p1->stmarks);
printf("you entered");
printf("name=%s\nroll number=%d\nmarks=%f",p1->stna me,p1->stroll,p1->stmarks);
getch();
}
void link()
{
float a,*p;
p=&a;
a=*p;
}