How to: Use same for-loop to fill different arrays?

Hello forum
I have the following code already filling my Array1 with numbers.
I would like the same two for-loops to also fill my Array2.

int Array1[9];
int Array2[9];

int data = 0;

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);
  
  for (int i = 0; i < 9; i++)
  {
    Array1[i] = data; // Is it possible to substitute "Array1" with some kind of variable?
    data++;
  }
  
  for (int i = 0; i < 9; i++)
  {
    Serial.print(Array1[i]);
  }

}

void loop() {
  // put your main code here, to run repeatedly: 
  
}

Is it possible to substitute the Array1 with a variable or something which could later point to Array2?

adding: Array2 = data; is not an option in this case, since I will have a lot of different arrays
Best regards
Joe

Hello user,

What about a multi dimensional array ?

Hello Guix
That may be possible. But I would like to know if there's some kind of variable I could use instead? :slight_smile:

Like a pointer?

int Array1[9];
int Array2[9];

int data = 0;

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);
  int *Array = Array1;  // or Array2
  for (int i = 0; i < 9; i++)
  {
    Array[i] = data; 
    data++;
  }
  
  for (int i = 0; i < 9; i++)
  {
    Serial.print(Array[i]);
  }

}

void loop() {
  // put your main code here, to run repeatedly: 
}