+ 1
Declaring a struct inside the same struct definition
How can I declare a struct inside the same struct definition: typedef struct{ int x; int y; point* nearest; } point; In this snippet I would like to have a pointer to the nearest point structure for each point structure, but it doesn't run. How can I do this?
1 Answer
+ 3
Look carefully
You are not declaring the same structure inside the structure, instead you are declaring a pointer variable pointing to same structure. Such thing is known as self referencing structure. It is quite usefull while implementing more complicated data structures like linked lists
Learn more about it heređ
https://www.geeksforgeeks.org/self-referential-structures/