Home / Programs / Write a program to add numbers given by the user through the use of pointers.
Programming Example

Write a program to add numbers given by the user through the use of pointers.

👁 23,846 Views
💻 Practical Program
📘 Step by Step Learning
Write a program to add numbers given by the user through the use of pointers.

Program Code

#include <stdio.h>
int main()
{
	int a,b,c;
	int *pa,*pb,*pc;
	pa=&a;
	pb=&b;
	pc=&c;
	printf("\n ENTER THE FIRST NUMBER:");
	scanf("%d",pa);
	printf("\n ENTER THE SECOND NUMBER:");
	scanf("%d",pb);
	*pc=*pa+*pb;
	printf("\n SUM IS %d",*pc);
	return 0;
}

Output


 ENTER THE FIRST NUMBER:12

 ENTER THE SECOND NUMBER:13

 SUM IS 25

Explanation

None

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.