23-pointer.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  4. *
  5. * This file is part of GNU Mes.
  6. *
  7. * GNU Mes is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * GNU Mes is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. char *g_hello = "hello";
  21. char g_arena[4] = "XXX";
  22. char *g_chars = g_arena;
  23. int
  24. main ()
  25. {
  26. if (*g_hello != 'h')
  27. return 1;
  28. if (g_hello[0] != 'h')
  29. return 2;
  30. if (g_chars[0] != 'X')
  31. return 3;
  32. if (*g_chars != 'X')
  33. return 4;
  34. g_arena[0] = 'A';
  35. if (*g_chars != 'A')
  36. return 5;
  37. char *x = g_arena;
  38. if (*x++ != 'A')
  39. return 5;
  40. *x++ = 'C';
  41. if (g_chars[1] != 'C')
  42. return 7;
  43. if (g_chars[2] != 'X')
  44. return 8;
  45. *--x = 'X';
  46. if (g_chars[1] != 'X')
  47. return 9;
  48. char **pp = &x;
  49. if (**pp != 'X')
  50. return 10;
  51. char *p = *pp;
  52. if (*p != 'X')
  53. return 11;
  54. char ***ppp = &pp;
  55. if (***ppp != 'X')
  56. return 12;
  57. char **pp2 = *ppp;
  58. if (**pp2 != 'X')
  59. return 13;
  60. return 0;
  61. }