1 / 5

Pointer to Structure

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

Télécharger la présentation

Pointer to Structure

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Pointer to Structure

  2. 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) iep=&a; in order to access the content of a  *p ie ‘a’ can be access using the pointer variable p • Like that a structure variable can be access using a pointer variable

  3. 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 student Since p and s are same type, p can store the address of the variable s Iep=&s; Now the content of p is address of s

  4. 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

  5. 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(); • }

More Related