Solved programming problem

Add two value with Pointer in C.

Source code

#include<stdio.h>

int main()

{

    int n,m;

    int add=0;

    int *ptr1,*ptr2; ///Declaring pointer variable

    printf("Please Enter the 1st Value: ");

    scanf("%d",&n);

    printf("Please Enter The 2nd Value: ");

    scanf("%d",&m);

    ptr1=&n; ///saving the variable address in to pointer

    ptr2=&m;

    add=*ptr1+*ptr2;  /// add the saved value in Pointer

    printf("
 Total: %d
",add);

    return 0;

}

Output

Please Enter the 1st Value: 6
Please Enter The 2nd Value: 7

 Total: 13

Join the discussion

Add your comment