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.P.S.: how do you input a literal asterisk on HN? Escaping with a backslash doesn't work, had to find a fancy unicode asterisk.
int p; type nameOfInstanceOfType;
int *p; notType notNameOfInstanceOfType;
How about something sane like: "pointer p = pointer(int)" or even Scalalike "pointer[int] p"? Pointers aren't so bad really. I think a lot of the hate for them is because the syntax begs you to fuck up. And inevitably you do. I mean, I just type random stuff until I get no warnings and things look like they work. Literally. That's how I program. How many asterisks here? I dunno, I'll just try zero through three and see if any of those work...
int* p;
Follows the Type NameOfVar pattern, though of course it breaks for multiple simultaneous declarations.As to your other point: it's legal for a pointer to an object to point one item past the end of the object. You may not read/write to this of course, but if you allocate 100 bytes of memory you may have char ∗start, and char ∗end = start+100. That's a nice concept taken to its limit in STL where all algorithms operate on abstract start; end+1 iterator pairs. So an empty sequence has start == end.
(Thanks to a sibling poster for the usage of ∗).
http://eli.thegreenplace.net/2009/10/21/are-pointers-and-arr...