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

Edit: I was wrong - see cygx's reply

---

I'm a bit rusty on the C spec, but I think the author is wrong about #4.

The answer refers to an exception for a pointer that points one past the end of an array.

And &a[5] would be valid based on that rule, because it points one past the end of the array a.

However (&a + 1) is not valid. It does not point one past the end of an array (because although a is an array, it is not an element of an array.)

Having said that I would be surprised if any compiler gave a result other than "2 5". Still, it's technically undefined.



See C99 6.5.6 §7:

For the purposes of these operators, a pointer to an object that is not an element of an array behaves the same as a pointer to the first element of an array of length one with the type of the object as its element type.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

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

Search: