I stumbled upon a "weird" behavior of malloc function. I'm looking for a way to allocate memory based on input from a user. I'm allocating one byte of memory, so as I understand, I'm creating a place for just one char variable, but when my input is a message with even over 100 characters, it prints out exactly the input. How is it possible that all of my input can fit in just one byte?
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char const *argv[])
{
char *nam = malloc(sizeof(char));
printf("Write your name:\n");
scanf("%s", nam);
printf("Your name is: %s", nam);
return 0;
}