News for hackers. Stuff that matters.
Re:Getting Past C by dbaupp on Tuesday January 03, 2017 @09:10PM (#13315119)
They don't, sizeof is a compile-time constant. On a pointer, sizeof() just reports the size of the pointer itself (i.e. 4 or 8 bytes on most modern platforms), not the size of the data to which it points (and sizeof(*pointer) reports the size of the type to which pointer points, it doesn't know anything about how many values of that type are stored). For an array, the length is known statically (i.e. it's in the type), and so the computation can be done at compile time.
Re:Getting Past C by steveklabnik on Tuesday January 03, 2017 @09:14PM (#13315134)
And this is such a misconception that it's often cited as a footgun: http://www.cplusplus.com/faq/sequences/arrays/sizeof-array/

> A beginner will often try something along the lines of size = sizeof( myarray ) (which is incorrect).

Re:Getting Past C by caf on Tuesday January 03, 2017 @09:51PM (#13315288)
sizeof isn't always a compile-time constant: if it's applied to variably-modified type, it's not (obviously).
Re:Getting Past C by dbaupp on Tuesday January 03, 2017 @10:20PM (#13315403)
Oh, yes, I'd forgotten about VLAs... Compile-time constant, except for sometimes.