#include<stdio.h>#include<stdlib.h>intmain(void){/*TO DO
* 1.allocate a chunk of memory by calling the malloc
* 2.add some memory based on initail memory by calling the realloc
*/size_t size =6;int* memory =(int*)malloc(size *sizeof(int));if(memory ==NULL){printf("falied to allocate the memory\n");free(memory);return1;}else{//sounds like if malloc success or not,after you used it you have to free //give value to avoid garbage valuefor(size_t i =0; i < size; i++){*(memory + i)= i +1;}//output the value of this chunk of memoryfor(size_t j =0; j < size; j++){printf("memory %zu:%d\n", j,*(memory + j));}}size_t newSize =10;int* new =(int*)realloc(memory, newSize *sizeof(int));if(new ==NULL){printf("falied to add memory based the old\n");free(memory);return1;}else{//update:give power from new to memory
memory = new;//give value to othersfor(size_t k = size; k < newSize; k++){*(memory + k)= k +1;}//output the value of this chunk of new memoryfor(size_t m =0; m < newSize; m++){printf("newMemory %zu: %d\n", m,*(memory + m));}}free(memory);return0;}