C program to add two numbers using pointers in C

In this article, we are going to learn the C program to add two numbers using pointers to add, subtract, multiply and Divide two numbers by using pointers.

C program to add two number using pointers


In this c program, we are asking users to input two numbers and store them in pointer variable and using these pointer two find sum of two entered variables.

#include <stdio.h>

int main()
{
// Declare 2 numbers
    int num1, num2;
    int	sum;
// Declare 2 integer pointers
    int *ptr1, *ptr2;

// Assign numbers address to pointers
    ptr1 = &num1; 
    ptr2 = &num2; 

    printf("Please enter two numbers for Addition: ");
    scanf("%d%d", ptr1, ptr2);

    sum = *ptr1 + *ptr2;

    printf("The Sum of Given Numbers is = %d", sum);

    return 0;
}

Output

Please enter two numbers for Addition: 5
8
The Sum of Given Numbers is = 13