what is pointer and structure explain with program
Pointers and structures
struct allowance
{
int basic_pay’
int da;
int hra;
int city_allowance;
};
struct employee
{
char name[10];
char department[10];
struct allowance a1;
}*ptr;
ptr->name, ptr->department, ptr->a1.basic_pay, ptr->a1.da,
ptr->a1.hra, ptr->a1.city_allowance
struct employee
{
int eid;
char name[10];
char dept[10];
}emp[5],*ptr;
ptr=emp;
ptr->eid
ptr-->name
ptr->dept
for(ptr=emp;ptr<emp+5;ptr++)
printf(“%d%s%s”,ptr->eid,ptr->name,ptr->dept);
We could also use the notation :
(*ptr).eid
(*ptr).name
(*ptr).dept
While using structure pointers, we should take care of the precedence of operators
The operators ->, . , ( ), [ ] enjoy the highest priority among the operators.
struct
{
int count;
float *p;
} *ptr;
++ptr->count;
Increments the count not ptr, however
(++ptr)->count;
First increments the ptr then links count.
struct employee
{
int eid;
char name[10];
char dept[10];
} emp,*ptr;
Now the members can be accessed in three ways :
Using dot operator : emp.eid, emp.name, emp.dept
Using indirection : (*ptr).eid, (*ptr).name, (*ptr).dept
Using selection notation : ptr->eid, ptr->name, ptr->dept