Upload
acton-bright
View
22
Download
0
Embed Size (px)
DESCRIPTION
Pointer to Structure. Pointer to Structure. Structure variable can be access using pointers int a=10,*p; Here p is an integer type pointer variable, p can hold the address of an integer(a) ie p=&a; in order to access the content of a *p - PowerPoint PPT Presentation
Citation preview
Pointer to Structure
Pointer to Structure• Structure variable can be access using pointers• int a=10,*p;
• Here p is an integer type pointer variable, p can hold the address of an integer(a)ie p=&a;in order to access the content of a *pie ‘a’ can be access using the pointer variable p• Like that a structure variable can be access using
a pointer variable
Pointer to Structure• let • struct student• {• char name[20];• int m1,m2,m3,total• };struct student s , *p;Now ‘s’ is the variable of type struct student ‘p’ is a pointer variable of type struct studentSince p and s are same type, p can store the address of the
variable sIe p=&s;Now the content of p is address of s
Pointer to Structure• The structure variable s can be access using p• With the help of point to operator (->)• ie• p->name equalant to s.name• p->m1 equalant to s.m1• p->m2 equalant to s.m2• p->m3 equalant to s.m3• p->total equalant to s.total
Pointer to Structure• void main()• {• struct check• {• int a;• char c[20];• };• struct check s,*p;• p=&s;• scanf("%d%s",&p->a,p->c);• printf("%d %s",p->a,p->c);• getch();• }