boot.dev lesson answers for the course: Learn Memory Management in C
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

13 lines
256 B

#include <stdlib.h>
#include <string.h>
void swap(void *vp1, void *vp2, size_t size) {
if (vp1 == vp2) return;
void *tmp = malloc(size);
if (tmp == NULL) return;
memcpy(tmp, vp1, size);
memcpy(vp1, vp2, size);
memcpy(vp2, tmp, size);
free(tmp);
}