Garbage value in char array.

alt text

Can’t figure out why??

Link to code : https://ideone.com/PMBINO

I think its because the char arrays are not null terminated. Try to add a ‘\0’ at the end of each char array, then print.

Actually as @yashv have pointed out you have not terminated your char arrays with a null character, But the main issue here is you are using %s to print the arrays. Now %s is used to print the strings and strings are expected to be null terminated in c so %s prints all the characters until it encounters a ‘\0’ (null character). So some garbage value is printed until %s encounters a null character.