// https://arduinogetstarted.com/faq/how-to-pass-array-to-function-in-arduino
// https://academy.programmingelectronics.com/pass-array-to-function-in-arduino/
// https://wokwi.com/projects/353414726659848193

int array_1[2] = {1, 2};
int array_2[4] = {1, 2, 3, 4};

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

  // pass by array type
  passByArrayType(array_1, 2);
  passByArrayType(array_2, 4);

  // pass by pointer type
  // int pointer_1 = &array_1; // warning: invalid conversion from 'int' to 'int*'
  // int pointer_2 = &array_2; // warning: invalid conversion from 'int' to 'int*'
  // passByPointerType(pointer_1, 2); // pass the address of array_1 // warning: invalid conversion from 'int' to 'int*' [-fpermissive]
  // passByPointerType(pointer_2, 4); // pass the address of array_2 // warning: invalid conversion from 'int' to 'int*' [-fpermissive]
}

void loop() {
}

void passByArrayType(int myArray[], int length) {
  for (byte i = 0; i < length; i++) {
    Serial.print(myArray[i]);
  }
  Serial.println();
}

void passByPointerType(int* myPointer, int length) { // note: initializing argument 1 of 'void passByPointerType(int*, int)'
  for (byte i = 0; i < length; i++) {
    Serial.print(*(myPointer + i));
  }
  Serial.println();
}