If I allocate a char array with size of 4 and then input 4 characters via scanf. The program works, but why? AFAIK, you need extra one space for null terminator, right? If I input 5 characters, it starts to show some errors:
*** stack smashing detected ***: <unknown> terminated
Aborted.
int main(int argc, char const *argv[])
{
char buffer[4];
scanf("%s", buffer);
printf("%s %d", buffer, strlen(buffer));
return 0;
}