Passing variable to function causes inconsistency

Hi i was working on a project and was using a bool array when something wasn't working. I managed to narrow it down to this:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  
  bool test[] = {true, true, false, true, true};
  
  Serial.println(sizeof(test));
  
  customPrintSize(test);

}
void customPrintSize(bool temp[])
{
  Serial.println(sizeof(temp));
}
void loop() {
  // put your main code here, to run repeatedly:

}

Serial monitor returns:

5
2

i have already worked around this problem by passing an extra variable containing the true size but was wondering why this occurs.
I am using Arduino 1.5.8 on windows 7 and sketch is running on moteino R4 (which has an atmega328)

accidentally replied my own post, well done me! (Y)

The size of the array is 5 bytes.
The size of the pointer to the array passed to the function is 2 bytes. The function can't tell how many bytes the pointer points to. If you want the function to know that value you should pass that value as another argument.

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  
  bool test[] = {true, true, false, true, true};
  
  Serial.println(sizeof test / sizeof test[0]);
  
  customPrintSize(test, sizeof test / sizeof test[0]);

}
void customPrintSize(bool temp[], int size)
{
  Serial.println(size);
}
void loop() {
  // put your main code here, to run repeatedly:

}

Ahh, thank you :slight_smile: