Does memcpy() uses realloc()?

Your code has Undefined Behavior. To answer your question, NO, memcpy doesn't use realloc. sizeof(buf) should be adequate to accomodate strlen(str). Anything less is a crash.

The output might be printed as it's a small program, but in real big code it will cause hard to debug errors. Change your code to,

const char* const str = "abcdefghijklmnopqrstuvwxyz";
char* const buff = (char*)malloc(strlen(str) + 1);

Also, don't do *buff++ because you will loose the memory record (what you allocated). After malloc() one should do free(buff) once the memory usage is over, else it's a memory leak.


You might be getting the whole string printed out, but it is not safe and you are writing to and reading from unallocated memory. This produces Undefined Behavior.

memcpy does not do any memory allocation. It simply reads from and writes to the locations you provide. It doesn't check that it is alright to do so, and in this case you're lucky if your program doesn't crash.