Part a) Write a function that takes two pointers-to-integers. The function makes
ID: 3691029 • Letter: P
Question
Part a) Write a function that takes two pointers-to-integers. The function makes both integers equal to the
smaller one. The function should have a return type ‘void’. Include the ‘main’ function with your answer.
Part b) The ‘main’ function has two integers (a, b) and two pointer (ptr1, ptr2). The main sets up the
pointer such that (ptr1a) and (ptr2b). Write a function that swaps the pointers such that (ptr1b) and
(ptr2a). The function return type should be ‘void’. Include the ‘main’ function with your answer.
Explanation / Answer
#include<stdio.h>
#include<conio.h>
void swap(int *ptr1a, int *ptr1b) {
int temp;
temp = *ptr1a;
*ptr1a = *ptr1b;
*ptr1b = temp;
}
int main() {
int a, b;
printf(" Enter the First number : ");
scanf("%d", &a);
printf(" Enter the Second number : ");
scanf("%d", &b);
swap(&a, &b);
printf(" First number : %d", a);
printf(" Second number : %d", b);
return (0);
}