Skip to main content
1 of 2
Junius L
  • 779
  • 1
  • 9
  • 13

Implementing realloc in C

I have an assignment to implement realloc in C, This's my code please review it.

void    *my_realloc(void *ptr, size_t len)
{
    void    *real;

    real = malloc(len);
    memset(real, 0, len);
    if (real)
        memcpy(real, ptr, len);
    free(ptr);
    return (real);
}
Junius L
  • 779
  • 1
  • 9
  • 13