# Thread: Question on typedef, structures

1. ## Question on typedef, structures

Is this possible? if so what does it mean?

Code:
```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 of statement 1 (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

2. I think it would be clearer for you if this:
Code:
```typedef struct tree{
int height;
int width;
int weight;
} banyan;```
Was re-written as:
Code:
```struct tree {
int height;
int width;
int weight;
};

typedef tree banyan;```
EDIT:
By the way, you might want to remove line numbers when posting. Post code that is well indented, and if possible, compilable.

3. Typedeffing struct names is not necessary in C++ (unlike C where you'd have to use the struct keyword everywhere you declare instances, unless the struct is typedeffed).

Line 7 creates an array for two pointers to this struct, but as long these are not set to point to anything, you cannot use them.

You probably meant to declare an array of two structs (not pointers to struct):
Code:
```7. banyan count[2]; // This is the statement I am interested in

8. count[0].height = 100;
9. count[0].width = 10;```
In C++ you could simply declare the struct as
Code:
```1. struct banyan{
2. int height;
3. int width;
4. int weight;
5. };```
and line 7 would work just the same.

4. Maybe check your other forums for replies?
Did you even bother to read it there before coming here?