Add Two number Using Pointer in C
Q. Write a C program to add two numbers using pointers.
#include <stdio.h>
#include <conio.h>
void main()
{
int i, j, *a, *b, sum;
clrscr();
printf("Enter two integers to add: ");
scanf("%d%d", &i, &j);
a = &i;
b = &j;
sum = *a + *b;
printf("Addition of the numbers is : %d\n", sum);
getch();
}
Q. Write an algorithm to add two numbers using pointers.
1. Start 2. Declare integer variables `i`, `j`, and `sum`. 3. Declare integer pointers `a` and `b`. 4. Prompt the user to enter two integers. 5. Read the two integers and store them in variables `i` and `j`. 6. Assign the address of `i` to pointer `a`. 7. Assign the address of `j` to pointer `b`. 8. Compute the sum by adding the values pointed to by `a` and `b`. 9. Store the result in variable `sum`. 10. Display the sum. 11. End.
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.
point.com