指標變數(交換數值)

 avatar
user_6817964
c_cpp
2 years ago
245 B
1
Indexable
Never
#include <stdio.h>

void swap(int *a, int *b) // a = &i; b = &j
{
    int temp = *a;
    *a = *b;
    *b = temp;
}


int main()
{
    int i = 3, j = 5;
    printf("%d %d\n", i, j);
    swap(&i, &j);
    printf("%d %d\n", i, j);
}