Can someone shed some light on self-referential pointer. Self-referential data types are the types containing the pointer or reference to their own kind but i want know about self-referential pointer. Can you please explain the term with some code.
Any links/resources to learn more about this would also be highly helpful.
Edit1:
Can you explain this:
The only self-referential pointer would be a
void *
And also there is this code which confuses me more:
int *p = (int*) &p;
Other than void*, there is no such thing as a self-referential pointer in C. That's because, if you were to write
foo* p;
foo* pp = &p;
where pp is a self-referential pointer, the types are not compatible, so compilation will fail. The only type for which compilation would pass is the case where foo is void and that's because you are allowed to convert a void** pointer to a void* pointer.
Really, you mean a self-referential type, such as can be found when implementing a linked list.
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