这是错误的使用交换功能? [等候接听]

时间:2022-06-07 18:52:30
void swap(int *x, int *y) {
    int temp;
    temp = *x;
    *x = *y;
    *y = temp;
}

int main() {
    int a=10, b=20;
    swap(a, b);
    printf("a: %d, b: %d", a, b);
}

I have error when it runs ..

它运行时我有错误..

1 个解决方案

#1


1  

u have to pass reference to swap method not values .

你必须传递对swap方法的引用而不是值。

int a=10, b=20;
swap(&a, &b);

#1


1  

u have to pass reference to swap method not values .

你必须传递对swap方法的引用而不是值。

int a=10, b=20;
swap(&a, &b);