0

I feel like this may be a very rudimentary, however, I just started learning C and it's been confusing me.

I'm trying to implement a linked list but several guides use different syntax when referencing nodes. Some use:

typedef struct node{
    int data;
    struct node* next;
}

while others use

typedef struct node{
    int data;
    struct node *next;
}

What is the difference between struct node* next vs struct node *next? And how does using one differ from the other in an actual program?

CIsNotFun
  • 1
  • 1

1 Answers1

0

The difference is, that the asterisk has a different position.

But in some circumstances, one is preferred over the other (not mandatory).

e.g.

//ptr1: pointer to char
//ptr2: pointer to char
char *ptr1, *ptr2;

vs

//ptr1: pointer to char
//ptr2: char
char* ptr1, ptr2; //to prevent some pitfalls like this
                  //assuming ptr2 should be a pointer too
Erdal Küçük
  • 4,810
  • 1
  • 6
  • 11