Mail Archives: djgpp/1999/04/27/22:10:53.1
Chris Mears wrote:
> > char string[100];
> > for (i = 0; i < sizeof (string) - 1; i++)
>
> In the for loop: i < sizeof (string)? Do you mean strlen() or
> something else? If I recall correctly, sizeof returns the number of
> bytes in a data type. So if string, in this case, is a constant pointer
> to char, wouldn't it be 2 or 4 bytes, not the dynamic length of the
> string?
It's not a dynamic length. And 'string' isn't a simple pointer. Using
sizeof on an array with a constant size will return the number of bytes in the
array.
char string[100];
char* a = string;
sizeof(a);
This will return 4, because 'a' is a (char *) and not an array. The real type
of 'string' is (char [100]) it just casts to a (char *) without any warnings.
--
(\/) Endlisnis (\/)
s257m AT unb DOT ca
Endlisnis AT BrunNet DOT Net
Endlisnis AT HotMail DOT com
ICQ: 32959047
- Raw text -