A question about chars and Serial I have the following code:

int count = 0;
char serial_char;
char serial_message[96];


void setup(){
  Serial.begin(9600);
}

void loop(){
  while(Serial.available() &gt; 0){

    serial_char = Serial.read();
    if (serial_char == '\n' || serial_char == '\r'){

      serial_message[count] = 0; // &lt;&lt;-- What does this line do?
      count = 0;
      Serial.println(serial_message);

    }
    else{
      serial_message[count++] = serial_char;
    }

  }

}


With this code, I can type a message into the serial monitor, and it will print the message back at me. So if I type 'Goodbye', it returns:

Goodbye


If I send it another message 'Word', it returns:

Word


However, my questions is when I comment out the line:

serial_message[count] = 0;


And then I repeat the same sequence of actions before, 'Goodbye' returns 'Goodbye', but when next I enter 'Word', it returns:

Wordbye


Could anyone explain this to me? I am really curious to know why this occurs. What does adding that 0 in the char array accomplish? Thank you.
The zero-value, the "null character", indicates the end of the string. For strings, you allocate some maximum space, in your case 96 bytes:

char serial_message[96];


When storing variable-length strings in that, you need to indicate where the string ends. That's what the zero value does in a null-terminated string. (Note that 0 is really binary 0x00 here; it's not the ASCII character 48, 0x30.) So, the 96 bytes allow for a string of at most 95 characters, followed by the terminator. When printing, it prints the memory contents until it finds that null character.