how to create a byte[] array function?

Hello ,
I want to create a function that use a byte array function from loop function

I have this created this function:

byte david [] = {0x30 , 0x35 , 0X5C ,  0X73 , 0X64 , 0X61 , 0x76 , 0x69 , 0x64 , 0x5C , 0x3B };

byte answer = MyFunction (david);

byte MyFunction (byte [] Array)

 byte lcs = 0;
  for (int i = 0 ; i < sizeof(Array); i++)
    lcs = lcs + Array[i];


  lcs = (byte)(0-lcs);
  Serial.println(lcs , HEX);
  return lcs;

but it doesn’t work ,
say “MyArray” was not declared in this scope…

Two things:

byte MyFunction (byte Array)
//should be
byte MyFunction (byte Array)

And you can't use sizeof(Array) in the function. If you want to know the length of the array in teh function, make that a second argument.

You must pass the size of the array to the function.

I don’t see MyArray anywhere in the code that you posted.

Perhaps if you posted all of it …

OK ,
now it's working , I have pass the size into the function.
I thought it can get it from the array in the function.

Thanks ,

I thought it can get it from the array in the function.

Arrays are passed to functions 'by reference' so instead of making a copy of the data it just passes a pointer to the data.

byte MyFunction (byte Array[])

is the same as:

byte MyFunction (byte *Array)

In your function, when you use the 'sizeof' operator, you are getting the size of the pointer.
There are libraries that implement an 'Array' class and that class has methods to get the size of the array (like "MyArray.length()") but those libraries typically take up more space than they are worth on a microcontroller like an Arduino.