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.
The C-string ends with a NUL-character and && is evaluated lazily, meaning that if the first statement is false/0 then the right hand statement will not be evaluated. So if ants[0] is NUL, ants[1] nor ants[2] would be accessed. Same if ants[1] is NUL.
Perhaps I should do like the C++ version and add some helper functions to build the Ast,
making the examples less verbose?
This comment is hidden because it contains spoiler information about the solution
Yes, of course, but most experienced C programmers find it easier to read without the extra ?: operator around the return value.
Not that it matters much here, but beware of the type of count... It would be better to use the same type for your ii variable.
The result of an expression in C is 0 (false) or 1 (true). Use the not operator (!) instead of the ?: operator:
return !(sum <= 0);
or better yet, reverse the comparision:
return sum > 0;
return (sum>0)? 1 : 0 ;
There is no need for the paranthesis around the expression, it just adds noise.
sum > 0 already has the value 1 or 0, so there is no need to convert it again, just return it:
return sum > 0;
return (result>0)?(true):(false);
There is no need to have paranthesis here, it only adds noise. ?: has lower priority than the less than operator and there is never any reason to have paranthesis around a single constant.
More importantly - you already have a boolean value, no need to convert it again to a boolean value, just return it:
return result > 0;
The i32 and f64 types both have the Copy trait. A type with the Copy trait does not have to be cloned when binding it,
it will automatically be cloned/copied.