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