Write a program that declares 2 integers and then add them using pointers.
Difficulty level
This exercise is mostly suitable for students
#include <stdio.h>
#include <conio.h>
void main()
{
int A, B, sum;
int *ptr1, *ptr2;
ptr1 = &A; // ptr1 stores the address of A
ptr2 = &B; // ptr2 stores the address of B
printf("Enter 2 intgers:");
scanf("%d %d", ptr1, ptr2);
// or scanf("%d %d", &A, &B);
sum = *ptr1 + *ptr2;
printf("%d + %d = %d\n", *ptr1, *ptr2, sum);
getch();
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Asymptotic Analysis 18