Array loses data after loop

Hello.
In my code, i set some values to an array, when i try to display it outside the loop (the code thats enclosed by /.../) it doesn't work. When i display it in the loop it does work exactly like i want it.
It seems like the array potFixed looses its data.
Why is that?

const int numOfPotentiometers = 5;
const int potPins[] = {A0,A1,A2,A3,A4};

void setup() {
  Serial.begin(9600);
}

void loop() {
MoveServo();  
}

int MoveServo() {
  int potRaw[] = {};
  int potFixed[] = {};
    for(int i = 0; i<numOfPotentiometers; i++) {
      potRaw[i] = analogRead(potPins[i]);
      potFixed[i] = map(potRaw[i],0,1023,0,180);
      Serial.print(potFixed[i]);
      Serial.print(", ");
    }
    
    delay(100);
  /*
    for(int i = 0; i<numOfPotentiometers; i++) {
    Serial.print(potFixed[i]);
    Serial.print(", ");
  }

  */
  Serial.println("");
}

int potFixed[] = {}; You reinitialise it every time.

Try qualifying it "static"

When you say it "doesn't work" you leave a lot of room for confusion. It does something and that something didn't meet your expectations. So what was the something it did and how did that compare or contrast with what you expected.

Right now it obviously doesn't print because the code to print it is commented out with the /* and */.

AWOL:
int potFixed[] = {}; You reinitialise it every time.

My first thought, but he also completely fills it and tries to print it (assuming he is uncommenting that part) in the same pass of the function so it should still print him something.

Also OP: You have another error in this code:

int MoveServo() {

You've declared that the MoveServo function will return an int. But you have no return statement anywhere in the function body. It isn't nice to lie to the compiler.

It seems like the array potFixed looses its data. Why is that?

int potFixed[] = {}; <- - - - <<<< this disappears/vaporizes when you leave the function, look up the meaning of SCOPE

As mention you are re-initializing it at the start of the function, use static int potFixed[] = {}; or make the array global.

Since the function doesn't exit between the time he fills the array and the time he tries to print it, what would be the point?

The problem isn't scope. The problem is that this:

int potFixed[] = {};

creates an array with 0 elements. Not very useful at all and when he tries to write to it later he is going out of bounds on the array with the first write.

You MUST either give an array a number of elements OR a set of initializers that it can count when you create it.

Sometimes you just can't see the obvious!

I want it to create an empty array when i call MyServo() and then fill it in with the current potentiometer value.
What I do not understand is even though I reinitialize it every time i should still be able to print the values of potFixed (in the MoveServo function)?
I re-edited the code below to showcase how i want to print it.

int MoveServo() {
  int potRaw[] = {};
  int potFixed[] = {};

    for(int i = 0; i<numOfPotentiometers; i++) {
      potRaw[i] = analogRead(potPins[i]);
      potFixed[i] = map(potRaw[i],0,1023,0,180);

    }  

    for(int i = 0; i<numOfPotentiometers; i++) {
    Serial.print(potFixed[i]);
    Serial.print(", ");
  }
  Serial.println("");
  delay(100):
}

That's no problem. But when you create this array you have to create an array that is large enough to hold what you want to put in there. If you create a 0 element array and then try to fill it you are writing out of bounds to the array.

int MoveServo() {
  int potRaw[numOfPotentiometers] = {};
  int potFixed[numOfPotentiometers] = {};

    for(int i = 0; i<numOfPotentiometers; i++) {
      potRaw[i] = analogRead(potPins[i]);
      potFixed[i] = map(potRaw[i],0,1023,0,180);

    }  

    for(int i = 0; i<numOfPotentiometers; i++) {
    Serial.print(potFixed[i]);
    Serial.print(", ");
  }
  Serial.println("");
  delay(100):
}

I want it to create an empty array when i call MyServo() and then fill it in with the current potentiometer value.

Creating an array of fixed size and known initial values is NOT the same as an empty array. An empty array has room for no elements. Not useful at all.

Delta_G:
That's no problem. But when you create this array you have to create an array that is large enough to hold what you want to put in there. If you create a 0 element array and then try to fill it you are writing out of bounds to the array.

int MoveServo() {

int potRaw[numOfPotentiometers] = {};
  int potFixed[numOfPotentiometers] = {};

for(int i = 0; i<numOfPotentiometers; i++) {
      potRaw[i] = analogRead(potPins[i]);
      potFixed[i] = map(potRaw[i],0,1023,0,180);

}

for(int i = 0; i<numOfPotentiometers; i++) {
    Serial.print(potFixed[i]);
    Serial.print(", ");
  }
  Serial.println("");
  delay(100):
}

Yes, that worked!
Thanks you all for helping me, I appreciate it!