0

Please help how make it work.

int myArray1[] = {10, 11, 12};
int myArray2[] = {15, 16, 17};


void setup() {
  Serial.begin(9600);
}

void loop() {

  myFunction(myArray1); delay(1000); // i want to use like this

}

void myFunction(int callArray) {
  for (int a = 0; a < 3; a++) {
    Serial.print(callArray[a]); Serial.print(" ");
  }
  Serial.println();
}
0

2 Answers 2

2

Add an asterisk to the function definition for myFunction. This compiles:

int myArray1[] = {10, 11, 12};
int myArray2[] = {15, 16, 17};


void setup() {
  Serial.begin(9600);
}

void loop() {

  myFunction(myArray1); delay(1000); // i want to use like this

}

void myFunction(int * callArray) {
  for (int a = 0; a < 3; a++) {
    Serial.print(callArray[a]); Serial.print(" ");
  }
  Serial.println();
}
0

One way is to declare the size in the function definition

int myArray1[] = {10, 11, 12};
int myArray2[] = {15, 16, 17};


void setup() {
  Serial.begin(9600);
}

void loop() {

  myFunction(myArray1); delay(1000); // i want to use like this

}

void myFunction(int callArray[3]) {
  for (int a = 0; a < 3; a++) {
    Serial.print(callArray[a]); Serial.print(" ");
  }
  Serial.println();
}
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.