malloc(0) actually works? [duplicate]
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: what’s the point in malloc(0)? Why does malloc(0) actually return a valid pointer for writing ? char *str = NULL; str = (char*)malloc(0); // allocate 0 bytes ? printf("Pointer of str: %p\n", str); strcpy(str, "A very long string ..................."); printf("Value of str: %s", str); free(str); // Causes crash if str is too long Output: Pointer of str: 0xa9d010 Aborted Value of str: A very long string ..........