Passing array to method different length?!

Hi,

I got a problem passing an byte array to a method:

byte letterA[5] = { B11111111,B11000011,B11111111,B11000011,B11000011 };

drawBitmap(1,1,letterA);
  
int bitmapSize = sizeof(letterA);
Serial.println("outside");
Serial.println(bitmapSize);


void drawBitmap(uint8_t x, uint8_t y, byte bitmap[]) 
{
  int bitmapSize = sizeof(bitmap);
  Serial.println("inside");
  Serial.println(bitmapSize);
  for(int i=0;i<bitmapSize;i++)
  {
    ledBuffer[i] = bitmap[i];
  }
}

The output is as follows:

outside
5
inside
2

Why does my array shrink to 2 inside the method?

Thanks in advance!

Short "answer": when passing array to function, always pass along the length of it too.

Answer to your question: 2 is the size of the pointer to the array not the array length. Why you get a 5 before? because at compile time, the compiler "knows" and replaces that sizeof() = 5.

Thanks for your reply!

So the function need to look like this?

void drawBitmap(uint8_t x, uint8_t y, byte bitmap[5])
{
  int bitmapSize = sizeof(bitmap);
  for(int i=0;i<bitmapSize;i++)
  {
    ledBuffer[i] = bitmap[i];
  }
}

or may I need to make it like this:

void drawBitmap(uint8_t x, uint8_t y, byte bitmap[], int bitmapSize)
{
  for(int i=0;i<bitmapSize;i++)
  {
    ledBuffer[i] = bitmap[i];
  }
}

exactly