+ 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

10th Sep 2020, 10:38 AM
Yogeshwaran P
Yogeshwaran P - avatar
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/
10th Sep 2020, 11:18 AM
Heng Jun Xi
Heng Jun Xi - avatar