The output has only 19 bytes even though the name array has the size of 20 bytes...

Yu Zhou Answered 1 answer
Question by Yu Zhou 5 years ago

Question

The output has only 19 bytes even though the name array has the size of 20 bytes, why is that?

Answers

Answered by Daniel McCarthy

Instructor

Hello,
Good question that is because we use a NULL terminator which is basically a byte thats equal to zero. This is what tells printf that a string has ended. When ever you define a string in C a NULL terminator is automatically prepended in memory. For example if we did printf("Hello"); the Hello looks like this in memory 'H', 'e', 'l', 'l, 'o', 0x00

Does that answer your question?