how to create structure pointer in c

Answer:
structure pointer in c is created following way:

struct haddin{
int cook;
float prior[3];
};
void main(){
struct haddin *ptr;
struct haddin strauss={5,3.0f,4.0f,5.0f};
ptr=&strauss;
clrscr();
printf("%d %f",ptr->cook,ptr->prior[1]);
getch();


}

Output: 5 4.000000
Explanation: Here ptr is pointer to structure haddin.

No comments: