Now in this program I tried to concatenate two strings but when I don't provide null character to it's end it produces a unknown value at the end. Now I know the importance of null character but I would to know what happened here to produce the random value at the end of concatenated string and what it is?
First code: With null character inserted
void main(){
char str1[10],str2[10],output_str[20];
int i=0,j=0,k=0;
printf("Insert first string: ");
gets(str1);
printf("Insert second string: ");
gets(str2);
while(str1[i] != '\0')
output_str[k++]=str1[i++];
while(str2[j] != '\0')
output_str[k++]=str2[j++];
/*This the line which matters*/
output_str[k]='\0';
puts(output_str);
}
Input: First string: Bhushan
Second string: Mendhe
Output: BhushanMendhe
But for the same above code with the same inputs, if I just remove 'The line which matters.' in the code.
Output is: BhushanMendhe0♥↕@
I want to understand why that bolded part in second output was produced when we didn't specify null character and what is it called?