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