There is a dynamic array of pointers

char ** pointer = (char **) calloc(count,sizeof(char*)); 

on the lines. It is necessary to remove elements from it, i.e. actually release the memory pointed to by this pointer, and then assign the pointer to NULL

The problem is that after, when outputting data, it displays "left" data, although in theory the address of this pointer should be 0x0 , when debugging, the pointer points to another address, not 0х0

 void delete_elem(char ** p){ char ** p_str = p; free(*p_str); p=NULL; } 
  • Are you sure that you only need to delete the first element? and yes, p=NULL; meaningless, this is a local variable. - pavel
  • I do not delete the first element, I pass to the function the address of the element of the array to be deleted. Then if the array will be global to assign NULL will make sense? - Hardc0re
  • @ Hardc0re It is not clear whether you want to delete the entire dynamically distributed array of pointers, or the memory pointed to by a certain element of the array. - Vlad from Moscow
  • I wanted to free firstly the memory to which the pointer was pointing, and then assign the pointer to NULL - Hardc0re

1 answer 1

Do you want that?

 void delete_elem(char *** p){ free(*p); *p=NULL; } char ** pointer = (char **) calloc(count,sizeof(char*)); delete_elem(&pointer); 

Only you have no memory for count pointers to char ? Through pointer[i] ? Is it really not necessary to release her?

  • @pavel Everything, enough for today, earned. Thank! - Harry