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