fork(1) download
  1. #include <stdio.h>
  2. void Swap(int x, int y);
  3. int main(void)
  4. {
  5. int a, b;
  6. printf("Please enter a,b:");
  7. scanf("%d,%d", &a, &b);
  8. printf("Before swap: a = %d, b = %d\n", a, b);/* 打印交换前的a,b */
  9. Swap(a, b); /* 按值调用函数Swap() */
  10. printf("After swap: a = %d, b = %d\n", a, b);/* 打印交换后的a,b */
  11. return 0;
  12. }
  13. void Swap(int x, int y)
  14. {
  15. int temp;
  16. temp = x; /* 执行图9-4(b)中的步骤① */
  17. x = y; /* 执行图9-4(b)中的步骤② */
  18. y = temp; /* 执行图9-4(b)中的步骤③ */
  19. }
Success #stdin #stdout 0s 544KB
stdin
1,3
stdout
Please enter a,b:Before swap: a = 1, b = 3
After swap: a = 1, b = 3