C Program to add two numbers using pointers with structure


In this program, You will learn how to add two numbers using pointers with the structure in c.


struct Test *ptr, t;

Example: How to add two numbers using pointers with the structure in c.

#include<stdio.h>

struct Test {
    int x, y, z;
};

int main() {

    struct Test *ptr, t;
    ptr = &t;

    printf("Enter two numbers:");
    scanf("%d%d", &ptr->x,&ptr->y);

    ptr->z = ptr->x + ptr->y;
    printf("Sum is:%d", ptr->z);

    return 0;
}

Output:

Enter two numbers:10 20
Sum is:30