3 AnswersNew Answer
And to add, if malloc() fails you should ideally return from the function or you will dereference a NULL pointer. This will leak memory if realloc() fails: arr->arr = realloc(arr->arr, arr->length * sizeof(int)); You should create a temporary variable to hold the return value of realloc() and assign it to your pointer if it successfully reallocated the memory block. int *tmp_arr = realloc(arr->arr, arr->length * sizeof(int)); if (tmp_arr) arr->arr = tmp_arr;
Robin I know i can do it with &arr and arr.arr[i]. But I tried to use -> operator. Now if I don't initialize the pointer with NULL it work. It's ok if i don't initialize a pointer in situations like this?
Robin Gen2oo Thanks!