About Me

My photo
Raipur, Chhattisgarh, India
Hi , I am Amit Thakur. I have worked as a QA Engineer for two years and as a Java Developer for one year in NIHILENT TECHNOLOGIES PVT. LTD., Pune.Currently I am working as DEAN (Research & Development) in Bhilai Institute of Technology, Raipur.

Tuesday, September 3, 2013

C Program 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.
#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 :

  1. Value Filed of Pointer Can Be Accessed Using ‘*’ Operator
  2. ‘*’ is value at Operator.
  3. Read ‘*ptr’ as ‘Value at Address ptr’.

No comments: