Skip to content

Commit a1f21cb

Browse files
committed
renamed: from pointer/q2
1 parent 6bc120a commit a1f21cb

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//WAP to swap two numbers using pointer.
2+
3+
#include <stdio.h>
4+
int swap(int *, int *);
5+
int main(){
6+
int a, b;
7+
int *ptr1 = &a, *ptr2 = &b;
8+
printf("Enter two numbers: ");
9+
scanf("%d%d", &a, &b);
10+
printf("Before Swap:\na = %d\tb = %d\n", a, b);
11+
swap(ptr1, ptr2);
12+
printf("After Swap:\na = %d\tb = %d\n", a, b);
13+
return 0;
14+
}
15+
int swap(int *ptr1, int *ptr2){
16+
int temp;
17+
temp = *ptr1;
18+
*ptr1 = *ptr2;
19+
*ptr2 = temp;
20+
return 0;
21+
}

0 commit comments

Comments
 (0)