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