交換變數(回傳東西)

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

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

    return 100 * a + b;
}


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