How to Multiply two numbers using pointers

In this post, we are going to how to Multiply two numbers using pointers with examples.

C Program to Multiply two numbers using pointers


In this c program, we are asking users to input two numbers and store these numbers in pointer variables, and using these pointers to find mutiplication of two numbers.

#include <stdio.h>

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

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

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

    mul = *ptr1 * *ptr2;

    printf("The Multiplication Results are = %d", mul);

    return 0;
}

Output

Please enter two numbers for Multiplication: 5
8
The Multiplication Results are = 40