The hi array was declared with a length of 3. It does not increase in size just because you concatenated another string to it. strlen(), however, uses the '\0' to find the end of the string so reports how many bytes the string takes
where is the extra now??
You wrote to memory that the program does not own so you may have overwritten another variable in the process
The hi array was declared with a length of 3. It does not increase in size just because you concatenated another string to it. strlen(), however, uses the '\0' to find the end of the string so...
...after it gets to the end of the space allocated to “hi” and hasn’t found a string terminator '\0', it keeps reading through memory it has no right accessing until it finds a zero byte and returns that length as the length of the string.
it keeps reading through memory it has no right accessing
The problem is not the reporting of the length of the concatenated string, which it does correctly, rather it is the writing to memory not allocated to the string in the first place
I had hoped to show that the "extra" array was getting overwritten by the strcat() but it didn't matter which order the declarations were in or whether they were local or global: the fourth line (when the sketch didn't crash) would show 'extra' undammaged.