Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing a pointer from a pointer array

Tags:

arrays

c

pointers

I am building a tree data structure, in which I have an array of pointers in every node (node* children[FIXED_SIZE]), that point to children (size of the array is fixed):

I want to have a child inside the child variable (without freeing memory associated with it) but I also want to delete link between parent and children. Am I doing it correctly?

node* child = NULL;
i=2;
child = parent->children[i];
parent->children[i] = NULL;
like image 363
syntagma Avatar asked Sep 01 '26 09:09

syntagma


1 Answers

Am I doing it correctly?

Assuming 2 is less then FIXED_SIZE, your code looks ok.


Referring your wording:

I want to have a child inside the child variable

child does not "have a child inside" but references, points to one.

like image 139
alk Avatar answered Sep 03 '26 23:09

alk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!