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 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.