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.
Some like to cast
malloc()
's result, some don't. It's a matter of taste, I guess. See e.g. https://en.wikipedia.org/wiki/C_dynamic_memory_allocation#Type_safetyif n==0 then result will be a dangling pointer in c.
I think you're right. I think the solution would be to add condition at the beginning that allocates n*sizeof if n>=3 otherwise 3*sizeof.
I think you're right. I think the solution would be to add condition at the beginning that allocates n*sizeof if n>=3 otherwise 3*sizeof.
this should return an error if n = 2 or n = 1
added a broken initial solution
@anaiel signature is an array of size 3 by definition
The else branch is unnecessary.
This comment is hidden because it contains spoiler information about the solution
Why you convert the type implicitly in malloc function?
It should be like "long long *result = (long long *)malloc(sizeof(long long) * n);", isn't, it?
This comment is hidden because it contains spoiler information about the solution
You're right, I thought there is something wrong with malloc because of order but not reviewed it in detail. Nice solution you made.
http://pubs.opengroup.org/onlinepubs/009695399/functions/malloc.html
"If size is 0, either a null pointer or a unique pointer that can be successfully passed to free() shall be returned."
You should check for "n==0" first, otherwise you would fill the memory, because the malloc won't get freed.
Maybe a problem in your code; it is not an issue.
Look at the top of the page to see how many people passed the C kata.
Cheers.
Loading more items...