Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
it makes sens now.Thank you so much for this wonderfull explanation
"sizeof" works at compile time, and returns the size of the type you're referring to. Using "sizeof" with a string only works if the string is stack allocated: char example[45] = "this is an example.", using "sizeof" here would return 45, rather than the actual length of the string. "strlen" counts the number of characters passed until it reaches the NULL byte. So "strlen" can be used on dynamically or stack allocated strings and return the correct size.
why you used strlen insteed of sizeof i didnt get it here? when we do sizeof we wont get the size of the string?
Unused memory isn't leaked. There's just a bunch of undefined bytes after the null byte. It still gets freed when the memory is freed using free, since the OS keeps track of the number of bytes allocated when you call malloc.
Imagine if this was an int array not a char array, a 0 in the middle of the array wouldn't cause any memory to leak.
This comment is hidden because it contains spoiler information about the solution
Thanks!
very nice one