Skip to content

Instantly share code, notes, and snippets.

@chintanparikh
Created December 8, 2013 08:44
Show Gist options
  • Save chintanparikh/7854725 to your computer and use it in GitHub Desktop.
Save chintanparikh/7854725 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#define swap_bytes(first, second) char* temp = malloc(sizeof(char)); *temp = *(char*)first; *(char*)first = *(char*)second; *(char*)second = *temp; free(temp);
int main()
{
char a = 'a';
char b = 'b';
printf("%c, %c\n", a, b);
swap_bytes(&a, &b);
printf("%c, %c\n", a, b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment