0

Let's say I have this definition:

typedef struct tnode *Tnodep;
typedef struct tnode
{
    int contents; /* contents of the node */
    Tnodep left, right; /* left and right children */
}Tnode;

What's does the last Tnode means? and what's the difference between this definition and this definition?

typedef struct tnode *Tnodep;
typedef struct tnode
{
    int contents; /* contents of the node */
    Tnodep left, right; /* left and right children */
};
celicoo
  • 1,100
  • 8
  • 18
  • 2
    Those aren't just structure definitions; they're also type aliases. The latter example should at least warn you at compile time that there is no name for the alias. The alias allows you to `Tnode var;` rather than `struct tnode var;`, for example. – WhozCraig Jan 10 '19 at 22:41
  • So putting just helps to not write "struct" ? – Yamen Massalha Jan 10 '19 at 22:44
  • @ODYN-Kon Yea, but my question is what will Tnode at the end help with? – Yamen Massalha Jan 10 '19 at 22:45

1 Answers1

1

The first definition defines a struct tnode, and two type names Tnodep and Tnode. The second one doesn't define the type name Tnode.

With the first definition, you can then define either of the following two:

Tnode x;
tnode y;

With the second definition, you can't. You can only write

struct tnode x;
gnasher729
  • 51,477
  • 5
  • 75
  • 98