#include <stdio.h> void swap(int *p1, int *p2) { int dummyVariable = *p1; //created a dummy variable to swap *p1 = *p2; *p2 = dummyVariable; } int main() { int a, b; scanf("%d %d", &a, &b); swap(&a, &b); printf("a = %d ", a); printf("b = %d", b); return 0; }
Using a third variable to swap
Test Cases
Test Results
Input
10 20
Expected Output
a = 20 b = 10