Storing an array pointer in an array!

PaulS:

OK, just realised what you are saying and that the array is created as a local variable and passed rather than the address.....

That's true here:

void setup() {

test1[0]="1"; test1[1]="2"; test1[2]="3";
test2[0]="one"; test2[1]="two"; test2[2]="three";
Serial.begin(115200);

testpassarray(test1);




It's not true here:


String test1[10] = {"1","2","3"};
String test2[10] = {"one","two","three"};
String *stored[100];
int numarrays=0;

void setup() {
  Serial.begin(115200);
  testpassarray(test1);




The first code pass a pointer to the local array to the function.
The second code passes a pointer to the global array to the function.



> So how can I pass the address of the global variable to the store function


Use the second code, there the array variable IS a global variable.



> How do I access the Strings of the global array whilst inside either function when I have the address?


Just like you are doing in the second code.

I don't understand how version 1 and version 2 are not the same. Both of the arrays are created globally I just stick the contents into the already created array in the original version and stick them in at the creation time in the second one.

  1. So how do I pass the address of the string array to the function?
  2. If I have the String array address how do I access the array itself?