C Program using pointers with structure


In this program, You will learn how to implement pointers with the structure in c.


struct Test *ptr, t;

Example: How to implement pointers with the structure in c.

#include<stdio.h>

struct Test {
    int x, y;
};

int main() {

    struct Test *ptr, t;

    ptr = &t;

    (*ptr).x = 10;
     //OR
    ptr->y = 20;

    printf("The x value is : %d", (*ptr).x);
    printf("\nThe y value is : %d", ptr->y);

    return 0;
}

Output:

The x value is : 10
The y value is : 20