Wanted to know if this is possible and if so what it means.

1 typedef struct tree{
2. int height;
3. int width;
4. int weight;
5. } banyan;

6. int main(){

7. banyan* count[2]; // This is the statement I am interested in

8. count[0].height = 100;
9. count[0].width = 10;

10. return 0;

}


I do know about typedefs. For eg, we can make an instance of the type tree because we have the statement typedef struct tree.
but what is the meaning of statement 7? where we are instantiating something of type banyan, which is an instance of type tree. banyan is just an instance isnt it?

The above program is just a sample. please let me know if something else has to be added for the above to make sense.

thanks

>For eg, we can make an instance of the type tree
>because we have the statement typedef struct tree.
C++ does that automatically. You don't need to use a typedef.

>banyan is just an instance isnt it?
banyan is a synonym for struct tree.

I am new to these forums. There are quite a few of them when I googled. So thought I'l try 3 of them.

and thanks for the link. Will follow the rules now on. like i said I am new to this.

just one more doubt, in the code below (I just added apple tree also) So in this case too, are tree, banyan and apple synonymous?

1 typedef struct tree{
2. int height;
3. int width;
4. int weight;
5. } banyan, apple;

6. int main(){

7. banyan* count[2]; // This is the statement I am interested in

8. count[0].height = 100;
9. count[0].width = 10;

10. return 0;

}

Edited 3 Years Ago by happygeek: fixed formatting

i guess what you want to do is create variables of type tree, for that you dont need to do typedef. you can say

tree banyan;
tree apple;

or else

struct tree{
int height;
int width;
int weight;
} banyan, apple;

and they will be two separate variables of type tree.

This article has been dead for over six months. Start a new discussion instead.