member_access.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* Copyright (C) 2022 Andrius Štikonas
  2. * This file is part of M2-Planet.
  3. *
  4. * M2-Planet is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * M2-Planet is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <stdlib.h>
  18. struct s
  19. {
  20. char x;
  21. int y;
  22. int z[3];
  23. };
  24. struct s a;
  25. int main() {
  26. a.x = 3;
  27. a.y = 5;
  28. if(a.x * a.y != 15) return 1;
  29. if((&a)->y != 5) return 2;
  30. a.z[0] = 1;
  31. a.z[1] = 2;
  32. a.z[2] = 3;
  33. if (a.z[0] + a.z[1] + a.z[2] != 6) return 3;
  34. struct s b;
  35. b.x = 3;
  36. b.y = 5;
  37. if(b.x * b.y != 15) return 4;
  38. if((&b)->y != 5) return 5;
  39. b.z[0] = 1;
  40. b.z[1] = 2;
  41. b.z[2] = 3;
  42. if(b.z[0] + b.z[1] + b.z[2] != 6) return 6;
  43. struct s* p = calloc(2, sizeof(struct s));
  44. p->x = 3;
  45. p[1].y = 4;
  46. if(p[0].x != 3) return 7;
  47. if(p[1].y != 4) return 8;
  48. return 0;
  49. }