Remove Duplicate Array Elements | C Programming Example

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Thanks for the video!

A sidenote: I believe returning a pointer to a heap allocated memory "is not" a good practice, as it makes the caller of function responsible for freeing the memory allocated by the callee.

I guess we should pass the adress of the pointer to the heap allocated memory in the caller function, to the callee:

```
void remove_duplicates(int array[], int length, int **new_array, int *new_length);

~~~

int *after = malloc(10 * sizeof(10))
int after_length = 0
remove_duplicates(test, 10, &after, &after_length)
```


In function definition we can use things like following:

```
(*after)[unique_count] = ...

~~~

*after = realloc(...)
```

Please let me know if I'm missing something.

reverseila