Is There a Way to Increment and Scroll through Declared Variables?

Something I've been wondering for a couple months, but always took the long way around to avoid being held up by it.

I want to have my program cycle through declared variables and read their values for my code. To better describe it, this is along the lines of what I'd like to do:

//Declare Arrays, all with the same "MyArray" beginning, just with different numbers on the tail.
int MyArray1 = {1,2,3};
int MyArray2 = {4,5,6};
int MyArray3 = {7,8,9};

void loop {

MyArray++; //This is the part that obviously doesn't work

if (MyArray[1] == 5) { Serial.print("Must be array #2!"); }

}

This is just an example but my code is much more complex, needless to say. I want to have a seemingly infinite amount of Arrays, so declaring them all would be not only time consuming but also not a proper solution. Can anyone add guidance on how to go about doing something like this? I figure there must be a way, but to be honest I'm not even sure what I'm looking for (so sorry if this has been asked before). Thanks in advance guys!

The typical way to do what you want is to put pointers to the arrays into a table:

int MyArray1[] = {1,2,3};
int MyArray2[] = {4,5,6};
int MyArray3[] = {7,8,9};

const int * (MyArray[]) = {MyArray1, MyArray2, MyArray3};

NOTE: C++ arrays start with index 0 so MyArray[0] points to MyArray1. This can get very confusing so you might want to name your arrays starting with 0.

And it's as easy as that! Thanks so much for the help, gotta love the Arduino community.

Multidimensional array.

Maybe I spoke too soon... So you can call the individual Arrays (let's say MyArray0) with the const int* MyArray[0]. Now I want to analyze the contents of that array, which are {1,2,3}. How can I go about doing that? Because I tried declaring another array - int CurrentArray - in which the contents of MyArray[0] would be transferred, but I get the error "invalid conversion from 'const int*' to 'int' ". This makes sense but I'm again unsure of how to approach this. Here's another example code to better illustrate what I'm talking about:

int MyArray0[] = {1,2,3}
int MyArray1[] = {4,5,6}
int MyArray2[] = {7,8,9}

const int * (MyArray[]) = {MyArray0, MyArray1, MyArray2};

void loop {

int x++;
CurrentArray[] = MyArray[x]; //This is the line it doesn't like

if (CurrentArray[1] == 5) {Serial.print("looks like it's array #2 again!");}


}

Thanks again in advance!

int x++;

What the heck is that?

It sounds like you want a two dimensional array...

int MyArray[3][3] ={
{1,2,3},
{4,5,6},
{7,8,9}
};

int CurrentArray;

void loop {

CurrentArray++;

if (MyArray[CurrentArray][1] == 5) {Serial.print("looks like it's array #2 again!");}


}

Try this:

int MyArray0[] = {1,2,3}
int MyArray1[] = {4,5,6}
int MyArray2[] = {7,8,9}

const int * (MyArray[]) = {MyArray0, MyArray1, MyArray2};

void loop 
{
  static int x;

  const int *CurrentArray = MyArray[x]; //This is the line it doesn't like
  if (CurrentArray[1] == 5) {Serial.print("looks like it's array #2 again!");}
  x = (++x) % (sizeof(MyArray)/sizeof(MyArray[0]));
}

Obviously const won't work if you intend to change the value in the arrays.