Using an unknown Array range

Can’t quite figure out what to search on as so far not finding what I want know.
In Pascal I can traverse an array with an unknown index count.

  for i:=myArray[LOW] to myArray[HIGH] do
  begin
    // Do something
  end;

Are there similar functions to “HIGH” and “LOW” in C++? I found some results but they rely on the items within the array being the same size, (going from memory here :slight_smile: )

  for (int i = 0; i < sizeOf(myArray) / sizeOf(myArray[0])...

I need to use char* arrays so each array item can be different lengths and sizeOf(myArray[0]) means nothing.

Thanks for any help.

Is it a properly terminated (with '\0') char array? If not, it should be.

Either terminate it with a '\0', or send a length in as a separate argument.

I found some results but they rely on the items within the array being the same size,

Each pointer in the array is an int. An int is 2 bytes so if you divide the sizeof(myArray) by 2 you will get the number of entries in the array no matter what data type the pointers relate to.

char * charArray[10];
int * intArray[120];
long * longArray[45];
float * floatArray[9];

void setup()
{
  Serial.begin(115200);
  Serial.println(sizeof(charArray) / 2);
  Serial.println(sizeof(intArray) / 2);
  Serial.println(sizeof(longArray) / 2);
  Serial.println(sizeof(floatArray) / 2);
}

void loop()
{
}

Output

10
120
45
9

UKHeliBob: Each pointer in the array is an int. An int is 2 bytes so if you divide the sizeof(myArray) by 2 you will get the number of entries in the array no matter what data type the pointers relate to.

Ahhhh, awesome, thanks HeliBob, it's easy to see what language I am fluent in and what I am not -- yet. :)