fork download
  1. #include <stdio.h>
  2.  
  3. void swap(int *x, int *y);
  4.  
  5. int main(void) {
  6. int data1[5] = {1,2,3,4,5};
  7. int data2[5] = {6,7,8,9,10};
  8.  
  9. //int *x;
  10. //int *y;
  11.  
  12. //x = data1;
  13. //y = data2;
  14.  
  15. for(int i=0;i<5;i++){
  16. swap(&data1[i], &data2[i]);
  17.  
  18. printf("配列data1[%d]:%d\n", i,data1[i]);
  19. printf("配列data2[%d]:%d\n", i,data2[i]);
  20. }
  21.  
  22. return 0;
  23. }
  24.  
  25. void swap(int *x, int *y) {
  26. int w;
  27. w = *x;
  28. *x = *y;
  29. *y = w;
  30. }
  31.  
Success #stdin #stdout 0s 5272KB
stdin
Standard input is empty
stdout
配列data1[0]:6
配列data2[0]:1
配列data1[1]:7
配列data2[1]:2
配列data1[2]:8
配列data2[2]:3
配列data1[3]:9
配列data2[3]:4
配列data1[4]:10
配列data2[4]:5