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