fork download
  1. #include <stdio.h>
  2.  
  3. void swap(int*x,int*y){
  4. int z=*x;
  5. *x=*y;
  6. *y=z;
  7. }
  8.  
  9. int main() {
  10. int data1[5]={1,2,3,4,5};
  11. int data2[5]={6,7,8,9,10};
  12. printf("変更前\n");
  13. for(int i=0;i<5;i++){
  14. printf("data1[%d]=%d data2[%d]=%d\n",i,data1[i],i,data2[i]);
  15. }
  16. printf("変更後\n");
  17. for(int i=0;i<5;i++){
  18. swap(&data1[i],&data2[i]);
  19. printf("data1[%d]=%d data2[%d]=%d\n",i,data1[i],i,data2[i]);
  20. }
  21.  
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
変更前
data1[0]=1 data2[0]=6
data1[1]=2 data2[1]=7
data1[2]=3 data2[2]=8
data1[3]=4 data2[3]=9
data1[4]=5 data2[4]=10
変更後
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