+ 5
Why does the output values are changing in the below two codes? Even though they are same codes.đ°
I created a two codes using single code.đ The only one difference between these two code is --------------------------------------------------------------------- the printf() function are swapped --------------------------------------------------------------------- (See those two code to understand clearly) But why the output are also changed in this two code? Please explain it ....đ And also tell how does output comes like this? https://code.sololearn.com/c1o0eq6YhhlX/?ref=app https://code.sololearn.com/cnY7bCxb0hDK/?ref=app
2 Answers
+ 1
Remove the 5 in char str1[5] = "hello";
I think it is related to the null character, '\0'
char array without it is not considered a c-string, therefore causing undefined behavior in strlen()
Details: https://www.thegeekstuff.com/2011/12/c-arrays/