fork(8) download
  1. #include <cstdio>
  2.  
  3. char *names[2] = {"mark", "stephen"};
  4. int ages[2] = {35, 21};
  5.  
  6. typedef struct
  7. {
  8. char *name;
  9. int age;
  10. }
  11. person;
  12.  
  13. void insert(person *p, char *name, int age)
  14. {
  15. p->name = name;
  16. p->age = age;
  17. }
  18.  
  19. int main()
  20. {
  21. person people[2];
  22.  
  23. for (int i = 0; i < 2; i++)
  24. {
  25. insert(&people[i], names[i], ages[i]);
  26. }
  27.  
  28. for (int i = 0; i < 2; i++)
  29. {
  30. printf("name: %s, age: %i\n", people[i].name, people[i].age);
  31. }
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0.02s 2680KB
stdin
Standard input is empty
stdout
name: mark, age: 35
name: stephen, age: 21