#include <stdio.h>
#include <stdlib.h>
int main()
{
    char* id;                                          
    int n;
    printf("enter the no of char you want\n");
    scanf("%d", &n);
    id = (char*)malloc((n+1)*sizeof(char));
    printf("enter the id\n");
    scanf("%s", id);
    printf("%s\n", id);
}
I am not able to understand this. I allocate memory of my desired length. Then I take a string as input (which otherwise not allowed) how is this possible and I am able to write more than the allocated chars and it is still printing.
