Ad
  • Custom User Avatar

    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.

  • Custom User Avatar

    Perhaps I should do like the C++ version and add some helper functions to build the Ast,
    making the examples less verbose?

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Yes, of course, but most experienced C programmers find it easier to read without the extra ?: operator around the return value.

  • Custom User Avatar

    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;

  • Custom User Avatar

    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;

  • Custom User Avatar

    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;

  • Custom User Avatar

    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.