0

Context: In helpers.c, I can make the sort function actually sort the values[] array.

Problem: However, I don't know how to re-inject this sorted array back in main without using pointers.

Question: How to "update" the haystack array via sort(haystack, size); when sort returns void, and haystack is a local variable, without using pointers ?

Indeed, if one could modify the definition of sort, it would be easy to modify haystack via something like haystack=sort(haystack, size);.

I could also change haystack directly in sort is the variable was global.

I don't want to use pointers, because it was not taught yet and thus there might be another solution I'd like to find.

0

haystack is a pointer to the first element of the array. Accessing an array element dereferences this pointer plus an offset calculated from the index. So any change you make to the array is also effective for the calling code.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .