Memset and sizeof

Hi Everyone.

memset(integerArray, 0, sizeof(integerArray));

How does sizeof know the size of an Array?

Take for example the following code where the Array size is not specified.

//http://www.gammon.com.au/serial
const unsigned int MAX_MESSAGE_LENGTH = 12;

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

void loop() {

 //Check to see if anything is available in the serial receive buffer
 while (Serial.available() _ 0)
 {
   //Create a place to hold the incoming message
   static char message[MAX_MESSAGE_LENGTH];
   static unsigned int message_pos = 0;

   //Read the next available byte in the serial receive buffer
   char inByte = Serial.read();

   //Message coming in (check not terminating character) and guard for over message size
   if ( inByte != '\n' && (message_pos - MAX_MESSAGE_LENGTH - 1) )
   {
     //Add the incoming byte to our message
     message[message_pos] = inByte;
     message_pos++;
   }
   //Full message received...
   else
   {
     //Add null character to string
     message[message_pos] = '\0';

     //Print the message (or do other things)
     Serial.println(message);

     //Reset for the next message
     message_pos = 0;
   }
 }
}

sizeof() alone cannot determine how many elements there are in an array unless it is an array of single bytes or chars. It returns the number of bytes used by the array

If you know the number of bytes used by each array element, which sizeof() can tell you, then you can calculate how many elements there are in the array

Where in the code is there an array whose size is not specified ?

I note that the code posted does not have a call to sizeof() or memset() in it

I see the line

const unsigned int MAX_MESSAGE_LENGTH = 12;

and I see the line

static char message[MAX_MESSAGE_LENGTH];

so the only array in your code has 12 elements. Why do you think that would result in an unspecified size?

I suspect that there may be some confusion in the original post relating to the use of the word "size". It could be taken to mean size in bytes or size as in number of elements.

Apology for my confusing question.

static char message[MAX_MESSAGE_LENGTH];

Refer to the above line , which option is correct?

memset(message ,0  ,sizeof (message));

or

memset(MAX_MESSAGE_LENGTH ,0  ,sizeof (MAX_MESSAGE_LENGTH));

Note that

memset(MAX_MESSAGE_LENGTH ,0  ,sizeof (MAX_MESSAGE_LENGTH));

is nonsense because its target is not the message array

@Delta_G
Thanks

@UKHeliBob
Thanks