Why does calling malloc() not make a difference?
问题 Here's a basic example: #include <all the basic stuff> int main(void) { char *name = (char *) malloc(2 * sizeof(char)); if(name == NULL) { fprintf(stderr, "Error: Unable to allocate enough memory!\n"); return EXIT_FAILURE; } strcpy(name, "Bob Smith"); printf("Name: %s\n", name); free(name); return EXIT_SUCCESS; } Because I'm only allocating 2 bytes of information (2 chars), there should be some sort of error when I perform strcpy, right? This doesn't happen, instead it just copies the string