Arithmetic Operations using pointers in C || Pointers || C Programming
In this, we are going to perform arithmetic operations by using Pointers in C Programming Language.


 
#include <stdio.h>
int main()
{
    //declare variables
    int x, y;
    int *ptr1, *ptr2;
    int sum, sub, mul;
    float div;
    printf("Enter the two numbers\n");
    scanf("%d %d", &x, &y);
    ptr1 = &x;    //ptr1 stores address of x
    ptr2 = &y;    //ptr2 stores address of y

    sum = (*ptr1) + (*ptr2);
    sub = (*ptr1) - (*ptr2);
    mul = (ptr1)(*ptr2);
    div = (*ptr1) / (*ptr2);
    
    printf("Sum=%d\n", sum);
    printf("Subtraction=%d\n", sub);
    printf("Multiplication=%d\n", mul);
    printf("Division=%f\n", div);
    return 0;
}

//..........Coded by Ananya Maurya

#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post