String is initialized to be all '\0' in C? -
i tried this:
char s[100]; for(int i=0; i<100; i++) { if(*(s+i) == '\0') printf("end of string\n"); }
and "end of string" printed 96 times. if change string definition char *s[120]; "end of string" 100 times
why that? how string initialized exactly.
i trying check every 3 char in string, need test going happen if pointer pass end of string.
edit: sorry, typo. should char s[100] instead of char *s[100]
if array s
automatic variable, pointers in array have indeterminate value. not initialized can de-reference or read without invoking undefined behaviour.
note: have array of pointers, not "string".
Comments
Post a Comment