Loading...
> Receiving input from the keyboard
View Course

Question by Yu Zhou

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

Answered by Daniel McCarthy

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?

Answered By Instructor