Only your first example has a character set with a null terminating character - the other two examples do not have a null termination, so you cannot use strlen() on them in a specific order.
char p[4]={'h','g','y'}; // p[3] is implicitly initialized to '\0' char p[3]={'h','g','y'}; // no room in p[] for a '\0' terminator char p[]={'h','g','y'}; // p[] implicitly sized to 3 - also no room for '\0'
Note that in the latter case, if you used a string literal to initialize the array, you will get a null terminator:
char p[]= "hgy"; // p[] has 4 elements, last one is '\0'
Michael burr
source share