#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    //initial mem allocation
    char *str;
    str = (char*)malloc(4); //from 4(3+\0): not overflow
    strcpy(str, "jin");
    printf("str = %s, adr of str = %p\n", str, str);

    //reallocating
    //str = (char*)realloc(str, 2); //overflow
    str = (char*)realloc(str, 11); //from 11(10+\0): not overflow

    strcat(str, " is coding");
    printf("str = %s, adr of str = %p\n", str, str);

    free(str);

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: