Skip to content

Instantly share code, notes, and snippets.

@chankruze
Last active June 1, 2019 18:46
Show Gist options
  • Save chankruze/4bdaa12bdf75bc1f67fcd8dbc9ccf7f8 to your computer and use it in GitHub Desktop.
Save chankruze/4bdaa12bdf75bc1f67fcd8dbc9ccf7f8 to your computer and use it in GitHub Desktop.
#include <stdio.h>
void swap(int *, int *); // The right way is to declare function prototype in header.
int main()
{
int a, b;
// printf("Enter the value of a:\n");
// scanf("%d", &a);
// printf("Enter the value of b:\n");
// scanf("%d", &a);
a = 10;
b = 20;
printf("[I] Before Swapping\n");
printf("==> a = %d\n", a);
printf("==> b = %d\n", b);
swap(&a, &b);
printf("\n[I] After Swapping\n");
printf("==> a = %d\n", a);
printf("==> b = %d\n", b);
return 0;
}
void swap(int *a, int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment