2 ms·
If you're curious why it works that way, you should read "The Development of the C Language" by Dennis Ritchie: http://cm.bell-labs.com/who/dmr/chist.html http:
by sltkr 12y ago
If you're curious why it works that way, you should read "The Development of the C Language" by Dennis Ritchie: http://cm.bell-labs.com/who/dmr/chist.html http://cm.bell-labs.com/who/dmr/chist.html
The short version is that in the early days, pointers where declared like "char p[]" and for arrays declared like "char buf[10]" a pointer was created, like this (in modern C):
char buf_storage[10]; /* this is not actually visible to the programmer */
char *buf = &buf_storage[0];
So pointers and arrays really were the same thing. Of course, this didn't fly anymore when structs were introduced (or when embedding arrays in structs was allowed, at least) so that's when arrays were introduced as a first-class type, with weird semantics so that existing code that used array variables as if they were pointer variables wouldn't break.