In a recursive method to group the external nodes of a tree, i need to allocate memory dynamically inside that function.But the statement
static node* ext_node = malloc (sizeof(node));
is not working, and compiler gives error,which says
initializer element is not constant.
In short i want to ask that how can i use the static keyword with a pointer in a recursive call when the memory to which the pointer is pointing is dynamically acquired?
I require this because, when it is required to add more element in the list, the method insert_to_end (node*) will take the responsibility of allocating the storage for new node, so with this i can create list of any length and that is too with exact memory requirement.
But how to achieve this in c language?
Aucun commentaire:
Enregistrer un commentaire