C语言交换两个int变量值(不使用第三个变量)
#include <stdio.h>
void swap(int *a, int *b) {
*a = *a + *b;
*b = *a - *b;
*a = *a - *b;
}
int main() {
int a = 3, b = 5;
printf('Before swap: a = %d, b = %d\n', a, b);
swap(&a, &b);
printf('After swap: a = %d, b = %d\n', a, b);
return 0;
}
原文地址: https://www.cveoy.top/t/topic/pdtW 著作权归作者所有。请勿转载和采集!