Is it posible to define a structure with a pointer to that type of structure? What I mean is:
typedef struct {
char* name;
node* parent;
} node;
As far as I tried or read, I don't know how to do this or if it's even possible.
Yes such structures are called self-referential structures.
Self Referential structures are those structures that have one or more pointers which point to the same type of structure, as their member.
Re: Copying structures containing pointers Normally, we can copy the structures in a two way. obj2=obj1; obj2. x1 = malloc(5*sizeof(int)); * And you can copy the structure using memcpy.
A nested structure in C is a structure within structure. One structure can be declared inside another structure in the same way structure members are declared inside a structure.
Yes, but you have to name the structure, so that you can refer to it.
typedef struct node_ {
char* name;
struct node_ * parent;
} node;
The name node
only becomes declared after the structure is fully defined.
You can use an incomplete type
in the typedef
:
typedef struct node node;
struct node {
char *name;
node *parent;
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With