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

Run it Now
#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