- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there any differencein the size of a variable of the followingtwo types?
1) struct node
{
long num;
char *c_ptr;
struct node *pred, *child;
int score;
}
2) typedef struct node *node_p;
struct node
{
long num;
char *c_ptr;
node_p *pred, *child;
int score;
}
Does the first declaration of struct "node" have more bytes in size?
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I wouldn't expect there to be a difference. What happens when you try a small testcase and use sizeof() and compare the size of two objects, one using the first decl and the other the second?
Max
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Although the size of the two structs are the same the contexts are different.
In the first example pred and child are pointers to "struct node". In the second example pred and child are pointers to pointers to"struct node".To beequivilent you need to take the "*" off of the pred and child in the 2nd case because node_p already declares a pointer and not the struct node.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
oh, yes, I should not have "*" in front of pred and child, I tested it and both structs have the same size. Thanks.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page