Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Structures, Pointers and typedefs (http://www.go4expert.com/forums/structures-pointers-typedefs-t8493/)

vinsudhir 27Jan2008 12:02

Structures, Pointers and typedefs
 
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. but what is the meaning of statement 7? where we are instantiating something of type banyan, which is actually something 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

Salem 27Jan2008 14:07

Re: Structures, Pointers and typedefs
 
The typedef just creates an alias (a single word), for some other type. Some types in C can be fairly complicated and it gets tedious and error prone to keep writing them out in full.

> banyan* count[2];
Is no different to
struct tree* count[2];

banyan IS NOT a new type, nor an instance of a tree.

A typedef doesn't create anything new, it's just a different way of referring to something else which already exists.

vinsudhir 27Jan2008 21:42

Re: Structures, Pointers and typedefs
 
thanks for the comments.

asadullah.ansari 28Jan2008 11:06

Re: Structures, Pointers and typedefs
 
Quote:

Originally Posted by vinsudhir
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. but what is the meaning of statement 7? where we are instantiating something of type banyan, which is actually something 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


First write any code in CODE BLOCK as per looking good and easily readable.

asadullah.ansari 28Jan2008 11:12

Re: Structures, Pointers and typedefs
 
You can say " 'banyan' is synonym of 'struct tree' " ..

asadullah.ansari 28Jan2008 11:16

Re: Structures, Pointers and typedefs
 
always use for code block.

Code:

.....
.....
.....

>>> For detail go to "code and guidlines" of this forum

vinsudhir 28Jan2008 13:14

Re: Structures, Pointers and typedefs
 
Ok. Thanks for the comments.


All times are GMT +5.5. The time now is 08:38.