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?
Yes. headerptr
is now equivalent to struct body*
.
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;
精彩评论