Basics of malloc and realloc approach are in this.