by Dinesh Thakur Category: Structure And Union

Pointers to structures may be declared as we declare pointers to any other data type. Like arrays and functions, the name of structure carries the address of the structure where the values of its various members are stored. Therefore, the pointer may be initialized by the name of structure which is a constant pointer to the structure. Program illustrates the declaration and use of pointer to a structure.

# include <stdio.h>

struct Health   // structure declaration
  char Name[20];
  int Age;
  int Height;
  int Weight;
} ;                          // end of structure
void main ()
  struct Health S1 = {"Dinesh", 36, 179, 72}, *S;
  S = &S1; // S is assigned the address of S1
  printf("Address of S1 = %X\n", &S1);
  printf("Size of S1 = %u\n", sizeof(S1));
  printf("Value of S = %X\n", S);
  printf ("Size of S = %u\n", sizeof(S));
  printf("Name of student= %s\n", S-> Name);
  printf("Ages of S1 = %d\n", S ->Age);
  printf("Height of S1 = %d\nWeight = %d\n", S->Height,S-> Weight);

C Program to Pointers to structures

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.