Search This Blog

Thursday, January 04, 2007

strlen&sizeof

strlen is a function calculating the length of a string,i.e.,'\0' excluded,
while sizeof is an operator calculating a variable's size when compiling,i.e.,if affect on a string,'\0' will be included.
just as is shown in this little programme:


#include <stdio.h>
#include <string.h>

#define s "hello"
int main ()
{

printf ("strlen:%d\n",strlen (s));
printf ("sizeof:%d\n",sizeof (s));
return 0;/*thank u,anonymous,haha*/
}

after executed,it outputs:
strlen:5
sizeof:6

1 comment:

Anonymous said...

return 0;

Don't forget that. ;-p