Pointers
Swap Using Pointers
Swap two variables using pointers passed to a function.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Swap two variables using pointers passed to a function.
#include <stdio.h>
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
int main() {
int a = 5, b = 10;
swap(&a, &b);
printf("a = %d, b = %d\n", a, b);
return 0;
}
a = 10, b = 5