睿宏 陳
PRO
last month
睿宏country asked

why isn't the second argument of fgets "sizeof(name) + 1 ?" We don't need to include the null terminator?

Udayan Shakya
Expert
last month
Udayan Shakya answered

Hello there! It's natural to be confused about the sizeof operator in C, and whether it includes the null terminator as well.

To answer your question: no, we don't need to write sizeof(name) + 1 because sizeof measures the full size of the variable (in bytes), which includes the null terminator as well.

Hope that helps! Contact us again if you have further questions.

C
This question was asked as part of the Learn C Programming course.