Structure Pointer in C Programming Language | Struct Pointer

Structure Pointer in C


  1. Home
  2.  
  3. C Programming Tutorial
  4.  
  5. Pointer to a Structure in C

Pointer to a Structure in C

 Last updated on July 27, 2020


We have already learned that a pointer is a variable which points to the address of another variable of any data type like intcharfloat etc. Similarly, we can have a pointer to structures, where a pointer variable can point to the address of a structure variable. Here is how we can declare a pointer to a structure variable.

 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
struct dog
{
    char name[10];
    char breed[10];
    int age;
    char color[10];
};

struct dog spike;

// declaring a pointer to a structure of type struct dog
struct dog *ptr_dog

This declares a pointer ptr_dog that can store the address of the variable of type struct dog. We can now assign the address of variable spike to ptr_dog using & operator.

ptr_dog = &spike;