Skip to content

Instantly share code, notes, and snippets.

@skalnik
Created April 14, 2009 16:55
Show Gist options
  • Save skalnik/95286 to your computer and use it in GitHub Desktop.
Save skalnik/95286 to your computer and use it in GitHub Desktop.
#include <stdio.h>
void swap_pointers(int **, int **);
int main() {
int i;
int arr1[] = {1, 2, 3};
int arr2[] = {9, 8, 7, 6};
int *p1 = arr1;
int *p2 = arr2;
swap_pointers(&p1, &p2);
for(i = 0; i < 4; ++i) {
printf("%d ", p1[i]);
}
for(i = 0; i < 3; ++i) {
printf("%d ", p2[i]);
}
}
void swap_pointers(int **a, int **b) {
int *t = *a;
*a = *b;
*b = t;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment