October 22, 2024
Chicago 12, Melborne City, USA
C#

Creating a struct referencing itself in C using custom type


I would like to create a struct with pointer to the property of the same type.

Ideally I would like to go for something like this, but this causes compilation error:

typedef struct {

  int data;
  Node *next;

} Node;

Solution I’m going for in this scenerio is:

typedef struct Node_s {

  int data;
  struct Node_s *next;

} Node_t;

Is it a valid approach or could it cause any obvious issues?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video