'Arduino or c++ working with array in parameter of function

void setup() {
  Serial.begin(9600);
  printArr([64,67]);
}

void loop() {}

void printArr(byte nilai[]) {
  for (byte c = 0; c < length(nilai); c++) {
    Serial.println(nilai[c]);
  }
}

I expect the program print char of number 64 and 67 in ASCII since it was iterated in array, but instead the compiler give me error

C:\Users\User\Documents\Arduino\sketch_apr18a\sketch_apr18a.ino:10:24: note: suggested alternative: 'long'
   for (byte c = 0; c < length(nilai); c++) {
                        ^~~~~~
                        long
exit status 1
expected identifier before numeric constant



Solution 1:[1]

A solving can be:

void setup() {
  Serial.begin(9600);
  byte arr [] = {64,67};
  printArr(arr, 2);
}

void loop() {}

void printArr(byte *nylai, unsigned d) {
  for (byte c = 0; c < d; c++) {
    Serial.println(*(nylai + c * sizeof(byte)));
  }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mihai8