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

Popular posts from this blog

node.js - How to mock a third-party api calls in the backend -

node.js - Why do I get "SOCKS connection failed. Connection not allowed by ruleset" for some .onion sites? -

matlab - 0-by-1 sym - What do I need to change in order to get proper symbolic results? -