Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void swap(void *a, void *b, size_t width)
- {
- void *temp = malloc(width);
- memcpy(temp, b, width);
- memcpy(b, a, width);
- memcpy(a, temp, width);
- free(temp);
- }
- int main() {
- char a = 'a', b = 'b';
- swap(&a, &b, sizeof(a));
- printf("%c %c\n", a, b);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement