Length of new array

Here, while defining the new array, +1 is taken along with the length of array for the null character. But why +1 is taken as a null character is not included in the length.

hi @sukritbansal01
null character is added so that the compiler knows when to stop reading the string. But for us, it has no significance,
For eg if there is a string “my_name”
it will look like this to the compiler: “my_name\0”
but for us, that null character is not needed, length of string should be what we can see, not what the compiler sees.

Exactly! Then why, here, we are taking +1 for the null character while creating the new array? That’s my question.

@sukritbansal01 the compiler still needs to store the null character, whether you can see it or not. So you need to provide space for it.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.