Monday, January 12, 2009

sizeof vs strlen

char str[]="abcd";
char *s="abcd";

strlen(s) = 4;
sizeof(s) = 2;
sizeof(str) = 5; =======> this include "\0" by default at end.
strlen("abcde\0") = 5 strlen() counts till it encounter a null value.

No comments:

Post a Comment