See it.
You have to write down the 1st element to the place of the 0th, then the 2nd to place the 1st, and so on. Then to the place of the last - 0th. So that this very 0th is not lost in the initial step, it should be saved into a temporary variable.
What are you doing? At the j
step, you write the j
element to the 0th place. That is, in a row, all the elements are written to zero. This is already wrong, right?
Then there is a complete disaster: *(mas-(n-1))
- this is the element with the index -(n-1)
, that is, 1-n
! There is no such element in the array, that is, you fall into a random area of memory. Then, *(mas+n)
also wrong: in the n
element array, the indices are from 0 to n-1
. Therefore, by the way, the cycle should be done not to n
, but only to n-1
.
It became clearer?
temp
- unused !!! - gecube