pc-ip-07.c¶
Problem Statement
Question 7: Write a program to swap two numbers using pointers using user-defined function.
Metadata¶
| Property | Detail |
|---|---|
| Author | Amit Dutta (amitdutta4255@gmail.com) |
| License | MIT |
Actions¶
💡 You can print or save this file by opening Raw and using your browser.
Source Code¶
#include <stdio.h>
void swap(int *, int *);
int main()
{
int a, b;
printf("Enter two number: ");
scanf("%d %d", &a, &b);
printf("\nBefore Swap: ");
printf("\nA = %d, Loc: %p", a, &a);
printf("\nB = %d, Loc: %p", b, &b);
swap(&a, &b);
printf("\nAfter Swap: ");
printf("\nA = %d, Loc: %p", a, &a);
printf("\nB = %d, Loc: %p", b, &b);
return 0;
}
void swap(int *a, int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}