Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

which would also illustrate what K&R said about array indices just being syntactic sugar for pointer arithmetic.

My mind has been blown.



If that blows your mind, you might want to avoid looking at the following: "foo"[2] == ("foo"+2) == (2+"foo") == 2["foo"]. And yes, you really can do that: in general a[b] and b[a] are exactly the same thing in C.


More C array pointer fun:

  *("abcdefg" + 3) == 'd'


sure as long as you don't care about stuff like unicode..


not quite. "foo"[2] is a char, ("foo"+2) is a string.


oh, bother, I forgot what HN does to asterisks. In what I wrote above, look for the bit in italics and mentally insert asterisks on each side of it. It was right when I typed it in, I promise...




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: