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.
Not a best practice, for sure.
Yes, but no.
Please use decimal "ones" or "zeros" when counting in decimal - binary "ones" and "zeros", though technically the same, don't like it very much to be misgendered that way - because they identify as binary :D
Thats so nice and clean - tried similar, but didn't knew you could use a for-loop as a lazy while-loop like that and I
also wasn't sure if bitshift-equals is a legal expression.
why the use of
size_t
insead ofunsigned
?== 0 is false
< 0 is true ?
how the loop stops when value == 0? can you explain?
Subtracting a size_t from a size_t is not well-defined when the result is negative. You should compare them first to ensure that the result is positive before subtracting them. Also, the use of the ternary operator here is just not necessary.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
many probs
I made such a dreadful solution in comparison to this one
I think it's much better to start the loop with the index 1, because you're already calculate the index 0 and 1, sorry for bad english:)
Hmmm - If you ever find yourself using 'true' or 'false' in a ternary operator statement like this, you should probably reconsider did you need to use a ternary operator in the first place ;-)
?!
You can absolutely have mutable strings on the stack.
char buf[11];
would work just fine for both your solutions.Seems like you got pointers and arrays confused. A pointer to a string literal (stored in the data segment) is not a "stack-allocated string". There's a significant difference between
const char *foo = "bar";
andchar foo[] = "bar";
.VLAs don't particularly factor into this, but they are absolutely mutable (seeing as they cannot be initialized, they would be useless otherwise). There is no such thing as "could" when dealing with well defined behaviours.
I think that making it static would not be a good idea.
Putting the string on the heap is important since we need writable memory. If you were to use so-called VLAs (e.g., a string allocated on the stack you could get non-writable memory). In C stack-allocated strings should be considered immutable.
Thus, going with malloc/calloc is a good idea here. Also freeing usually is implemented to be almost constant time, so there's no need to worry about that.
I hope I didn't misunderstand what you meant by static :'D
Loading more items...