Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save henrybear327/6608dd2866a371798c58 to your computer and use it in GitHub Desktop.
Save henrybear327/6608dd2866a371798c58 to your computer and use it in GitHub Desktop.
7-1-4 how to use function to do array swap.c
#include <stdio.h>
#include <stdlib.h>
void func(int []);
int main()
{
int a[2] = {3,6};
printf("Original %d %d\n", a[0], a[1]);
func(a);
printf("Modified %d %d\n", a[0], a[1]);
return 0;
}
void func(int a[])
{
int temp;
temp = a[0];
a[0] = a[1];
a[1] = temp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment