Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        2年前关闭。
                                                                                            
                
        
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);
}


运行时出现错误..

最佳答案

您必须将引用传递给交换方法而不是值。

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

关于c - 使用交换功能是否错误? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52244333/

10-15 03:46