Ad
  • Default User Avatar

    @lowlight

    your malloc() doesnt do anything, it just leaks memory. it is overwritten by the first pass of your for loop. Re-assigning integers inside your function will not affect its value outside of your function. Besides, your are assigning an address to an integer, the compiler most likely warned you about this:

    warning: assignment to ‘int’ from ‘void *’ makes integer from pointer without a cast [-Wint-conversion]
    

    This is because *integers points to the first element of the array; i.e. to an int. But even if you had written integers = malloc(...), this would make no sense, because the caller would not see the change: through the function call your are given a copy of the address of integers. If you wanted to change what integers point to, your function would need to take an int **, not an int *.

    its not specified

    It is specified by a comment in the initial code, which is still there in your solution:

    assign function results to provided array

  • Custom User Avatar

    integers is already preallocated by the tests and it is ensured that it is big enough to hold the result.
    The ++ just moves the pointer forward.