Implementation of string tokenizer function(par2)

The instructor has initialized char array str [] with a string in main function then why he is initializing an array to ouput pointer with size 1 more than input array because in previous video lectures the instructor himself has told that whenever we initialize a character array with a string than null is already present in it and we don’t need to add it additionally to the string so in the statement char * output = new char[strlen(input) + 1]; why there is an additional + 1, because from above reasoning input contain reference of an char array which already has null embedded in it, that is it already accounts for space for null char than why he has added extra + 1

Hi divya
The null char is embedded in the given storage only, no additional space is provided for it. So if you declare a char array of size 10, you can store only 9 char as 1 char is reserved for null char.
strlen(input) gives size of input chars excluding null, therefore we have to add one more space for null.

Hope it helps:)

Means are you saying any char array we create one space is autoatically reserved for null array like char a[10] will have one space booked for null and only rest 9 spaces are available for storing other chars

yes, it is true in case of character array.

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.