C Program to Add Two Numbers Using Pointer !
Program : How to Add Two Numbers Using Pointer ?
In this program we are going to accept two numbers from user using pointer. After accepting two numbers we are going to add two numbers by using de-reference operator in Pointer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #include<stdio.h> int main() { int *ptr1, *ptr2; int num; printf("\nEnter two numbers : "); scanf("%d %d", ptr1, ptr2); num = *ptr1 + *ptr2; printf("Sum = %d", num); return (0); } |
Output :
1 2 | Enter two numbers : 2 3 Sum = 5 |
Note :
- Value Filed of Pointer Can Be Accessed Using ‘*’ Operator
- ‘*’ is value at Operator.
- Read ‘*ptr’ as ‘Value at Address ptr’.