2

Possible Duplicate:
Typedef pointers a good idea?

I am confused with the following:

typedef struct body *headerptr;

Now, when I create something with type headptr that points to a struct body, to create a new headerptr would be as follows (I'm not sure if I'm doing this correctly):

headerptr newHeadptr;

Am I correct to assume that this would be a pointer that points to a struct body?

Community
  • 1
  • 1
diesel
  • 3,337
  • 4
  • 20
  • 16

2 Answers2

4

Yes. headerptr is now equivalent to struct body*.

flight
  • 7,162
  • 4
  • 24
  • 31
2

This would be a pointer that points to a struct body.

The way you've declared it, newHeadptr could point to a struct body. Remember, though, that you haven't allocated a struct body for it to point to. Initially, newHeadptr will just have some garbage value. To rectify that, you could to this:

headerptr newHeaderptr = malloc(sizeof(*newHeaderptr));

or:

struct body newBody;
headerptr newHeaderptr = &newBody;
Caleb
  • 124,013
  • 19
  • 183
  • 272