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.
#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 :
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’.
No comments:
Post a Comment