The function to reduce each element of the array to the value of the first element. At the entrance of the array and its length. It works only for the first element.

void romdomdom(double * firstel,int * otrlen){ double *rovn=firstel; for(int i=0;i<*otrlen;i++){ *(firstel+i)=*(firstel+i)-*rovn; } } 

Everything works if done so with the creation of a variable

 void romdomdom(double * firstel,int * otrlen){ double rovn=*firstel; for(int i=0;i<*otrlen;i++){ *(firstel+i)=*(firstel+i)-rovn; } } 

It is not clear why the first option does not work only through pointers.

    1 answer 1

    She can't work at all -

     for(int i;i<*otrlen;i++) 

    because the initial value of i not set!

    Write

     for(int i = 0; i < *otrlen; i++) 

    And yet - in the second case, you memorize the first value and subtract this memorized value, which was before the changes .

    And in the second - just reset the first element, and then you subtract this zero from the rest of the first element from the rest ...

    Workaround: :)

     for(int i = *otrlen-1; i >= 0; i--) 
    • I wrote from memory i = 0 forgot, it was there, I would correct the question - Slava32768