Skip to content

Instantly share code, notes, and snippets.

@mbalayil
Created May 3, 2011 06:16
Show Gist options
  • Save mbalayil/952885 to your computer and use it in GitHub Desktop.
Save mbalayil/952885 to your computer and use it in GitHub Desktop.
Swapping without using a temporary variable in C - Addition & Subtraction
/**
* Swapping without using a temporary variable in C
* (Addition & Subtraction)
**/
#include<stdio.h>
int main(void)
{
int a = 5, b = 10;
printf("Initially, a = %d and b = %d\n", a, b);
a = a + b;
b = a - b;
a = a - b;
printf("After swapping, a = %d and b = %d\n", a, b);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment