fork(1) download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. struct data
  5. {
  6. char name[10];
  7. int math;
  8. };
  9.  
  10. void swap(struct data *p1,struct data *p2)
  11. {
  12. struct data tmp;
  13. tmp=*p1;
  14. *p1=*p2;
  15. *p2=tmp;
  16. };
  17.  
  18. int main()
  19. {
  20. struct data student[2]={{"john",100},{"tom",90}};
  21. swap(&student[0],&student[1]);
  22. printf("%s got %d\n",student[1].name,student[1].math);
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 2248KB
stdin
Standard input is empty
stdout
john got 100