Cのポインタの読み方は、ルールを知らないと摩訶不思議です。

ルールを覚えれば、

int (*p[5])[3];
char (*(*fp)(void))(int);
なんてのも解読する事ができます。

—- 大事な前程
ポインタを読む際には、「英語で読む」必要があります。

「え~、英語~」 と思う方もいるかもしれませんが、逆に日本語で読む方が大変です。

—- 基本ルール
ルール

後置演算子が優先。
関数の()
配列の[]
前置はあとで。
要は、「後ろに何かあったら、後ろが優先」です。

演算子の英語での読み方

* pointer to …
() function returning …
[] array of …

c_pointer

なるほど。普段は無意識に後置優先読みをしていたのだが、それを英語で置き換えて読めば一発だね。

(via kashino)

  1. whatta reblogged this from kashino
  2. qawsklp reblogged this from toby-net and added:
    kashino)うげぇ
  3. shino reblogged this from kashino
  4. kenta0101 reblogged this from atm09td
  5. haguy reblogged this from atm09td
  6. bokuwabokudayo reblogged this from muratayusuke
  7. noonoon reblogged this from mamemomonga
  8. layzie313 reblogged this from toby-net
  9. hugakusan reblogged this from yt-siden
  10. yt-siden reblogged this from jun26
  11. takashi0215 reblogged this from atm09td
  12. takashi0215 reblogged this from atm09td
  13. shineon964 reblogged this from toby-net
  14. seapomeranian reblogged this from atm09td
  15. gonfreak reblogged this from kashino
  16. muratayusuke reblogged this from atm09td
  17. readmaster reblogged this from toby-net
  18. mamemomonga reblogged this from jun26
  19. atm09td reblogged this from toby-net
  20. functionn reblogged this from kashino
  21. jun26 reblogged this from toby-net
  22. toby-net reblogged this from kashino
  23. nag reblogged this from kashino
  24. shayol reblogged this from kashino
  25. 8ue reblogged this from kashino
  26. naozine reblogged this from kashino
  27. gijibamboo reblogged this from kashino
  28. ukar reblogged this from kashino
  29. kashino posted this
Short URL for this post: http://tmblr.co/Zu2ELyEw00qw