·  C – Syntax – Pointers – To Struct

 

- Info:

  - This tutorial is based on http://publications.gbdirect.co.uk/c_book/chapter6/structures.html.

 

- Example:

  - This example shows basic operations with pointers to structures.

  - Create C Console Application Test.c.

 

    Test.c

    #include <stdio.h>

   

    int main() {

   

      /* DECLARE STRUCT PERSON. */

      struct person{

        int  id;

        char password[10];

      } john;

   

      /* CREATE POINTER TO STRUCTURE PERSON. */

      struct person *pts = &john;

   

      /* ACCESS VALUE OF STRUCT VARIABLES. */

      (*pts).id = 20;

        pts->id = 20;

   

      /* GET VALUE OF STRUCT VARIABLES. */

      printf("%i", john.id);

   

      return 1;

   

    }