Created
November 16, 2014 07:50
-
-
Save henrybear327/6608dd2866a371798c58 to your computer and use it in GitHub Desktop.
7-1-4 how to use function to do array swap.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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