Buffer Overflow issue

Here temptime buffer will hold only 11 byte, but when i declared temptime as 11 byte (char temptime[11]),arduino will restarted . but when temptime is 12 byte no issue.
where come this extra byte?

char temptime[12]
sprintf(temptime, "%02d:%02d:%02s",23,34,"12.00");

Thanks.

strings have a '\0' as their terminator so you need to allow space for it

I think temptime[11] contains ''\0" ,then why other extra byte??

temptime[11] can hold 11 bytes
How many bytes are in the output from your sprintf() that you put into temptime ?

23:34:12:00 + the '\0'

output from sprintf is 11 byte but my doubt is temptime start at index 0, so temptime [12] empty,right??

woundr:
Here temptime buffer will hold only 11 byte, but when i declared temptime as 11 byte (char temptime[11]),arduino will restarted . but when temptime is 12 byte no issue.

I always make my arrays a few characters longer than the longest thing I think I will need. Wasting a few bytes causes no problem but writing past the end of a too-small array does.

...R

woundr:
output from sprintf is 11 byte but my doubt is temptime start at index 0, so temptime [12] empty,right??

When you define an array char temptime[12]; the elements of the array are numbered 0 to 11 and temptime[12] does not exist. When you define an array the number in square brackets is the length of the array and not the index number of the highest element.

...R

output from sprintf is 11 byte

Is it ?

23:34:12:00 is 11 bytes but there is a '\0' on the end which comes from the "12:00", making a total of 12 bytes

You are putting 12 bytes into an array of 11 bytes so are writing outside of the memory allocated to the array. That is why declaring temptime[12] makes it work OK

my doubt is temptime start at index 0, so temptime [12] empty,right??

No matter whether temptime is declared as 11 bytes or 12 bytes there is no array level temptime[12] because the index start at zero

well understood ..Thanks a lot for all