fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4.  
  5. struct SSS {
  6. char dummy[256];
  7. int num;
  8. };
  9.  
  10. void print_data1(struct SSS *d, char *name)
  11. {
  12. printf("%s = { [0]%d, [1]%d }\n", name, d[0].num, d[1].num);
  13. }
  14.  
  15. void print_data2(struct SSS **d, char *name)
  16. {
  17. printf("%s = { [0]%d, [1]%d }\n", name, d[0]->num, d[1]->num);
  18. }
  19.  
  20. int main()
  21. {
  22. struct SSS s1[2];
  23. struct SSS *s2;
  24. struct SSS **s3;
  25.  
  26. // s1
  27. memset(s1, 0xFF, sizeof(s1));
  28. s1[0].num = 10;
  29. s1[1].num = 11;
  30. print_data1(s1, "s1");
  31.  
  32. // s2
  33. s2 = (struct SSS *) malloc(sizeof(struct SSS) * 2);
  34. memset(s2, 0xFF, sizeof(struct SSS) * 2);
  35. s2[0].num = 20;
  36. s2[1].num = 21;
  37. print_data1(s2, "s2");
  38.  
  39. // s3
  40. s3 = (struct SSS **) malloc(sizeof(struct SSS *) * 2);
  41. s3[0] = (struct SSS *) malloc(sizeof(struct SSS));
  42. s3[1] = (struct SSS *) malloc(sizeof(struct SSS));
  43. s3[0]->num = 30;
  44. s3[1]->num = 31;
  45. print_data1( s3, "s3(×)");
  46. print_data1(*s3, "s3(×)");
  47. print_data2( s3, "s3(○)");
  48.  
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0.02s 1808KB
stdin
Standard input is empty
stdout
s1 = { [0]10, [1]11 }
s2 = { [0]20, [1]21 }
s3(×) = { [0]0, [1]0 }
s3(×) = { [0]30, [1]0 }
s3(○) = { [0]30, [1]31 }