Created
November 29, 2018 11:23
-
-
Save dbc2201/a2d3ff8a7747d9dc64ad93e0f4ad526e to your computer and use it in GitHub Desktop.
Swap two variables using pointers.
Call By Reference
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> | |
void swap(int *a1, int *b1); | |
int main() | |
{ | |
int a = 4, b = 5; | |
printf("a = %d b = %d\n", a, b); | |
swap(&a, &b); | |
printf("a = %d b = %d\n", a, b); | |
return 0; | |
} | |
void swap(int *a1, int *b1) | |
{ | |
*a1 = *a1 + *b1; | |
*b1 = *a1 - *b1; | |
*a1 = *a1 - *b1; | |
printf("%d %d\n", *a1, *b1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment