交换两个变量值(交换成功)

Run Settings
LanguageC
Language Version
Run Command
#include <stdio.h> // 参数为指针变量 *理解为只是个标志?该参数为指针变量?不进行取值运算。 void swap2Variable(int *a, int *b) { printf("a is %p,b is %p\n", a, b); int temp; temp = *a; // 这里 temp 保存的是整数值 3 *a = *b; *b = temp; printf("temp %d\n\n",temp); printf("a is %p,b is %p\n", a, b); } int main() { int num1 = 3, num2 = 5; printf("before swap: num1 is %d, num2 is %d\n", num1, num2); swap2Variable(&num1, &num2); printf("after swap: num1 is %d, num2 is %d\n", num1, num2); // 函数执行完成后,结果没有变化 } // swap2Variable 传递的是变量对应内存单元的首地址。
Editor Settings
Theme
Key bindings
Full width
Lines