On Fri, 20 Jul 2001, Robert E. Griffith wrote: > One thing to keep in mind is that C has a few notation short cuts that make > things less consistant. > > Char buffer[20]; > > This one statement does several things. > > 1) it sets aside 20 bytes (each char is 1 byte) of memory. > 2) it declares a char* named 'buffer' > 3) it sets the value of the char* buffer to the beginning of the memory it > set aside. > > Number 2 is the confusing part. It does not look like you are declaring a > pointer, but in most respects buffer behaves as if it was declared "char* > buffer" 2 and 3 are false, if you think of `buffer' as a pointer (because it isn't). Actually, `buffer' behaves perfectly consistently if you think of it as a constant which happens to have type (char *), just as 1 is a constant that happens to have type (int). The value of the constant `buffer' is the address of the start of the array you declared. > The next confusing thing; Variables of type char* are assumed to point to a > memory location that has 0 or more byte values that correspond to ASCII > characters (65 means 'A' and is OK, 200 means nothing in ASCII and is not > OK) and ending in the value 0 (NULL). The 0 lets functions know how long > the string is. Actually, this is false, if you mean that the C compiler assumes this. It is a convention applied by some library functions. (I should say that I'm talking about `real' C compilers; there are probably some brain-damaged ones that make this kind of assumption.) > The C compiler sets aside memory for string literals (like "dog") with one > extra byte that it sets to 0 (NULL). This is true. John. -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads