struct and typedef in C

structs are the historic predecessors of classes. So just as you would declare a class type called MyClass in C++ or Java:

class MyClass {
    [...]
};

so would you declare a struct type called MyStruct in C:

struct MyStruct {
    [...]
};

What trips people up is that in C, you can declare an instance of a struct type in the same breath that you declare the struct type:

struct MyStruct {
    [...]
} instanceOfMyStruct;

Note that this also allows you to create instances of anonymous struct types:

struct {
    [...]
} instanceOfNamelessStruct;

Now, enter typedef, which lets you create an alias type for some other type, i.e.:

typedef uint32_t AccountNumber;

This says that AccountNumber is another name for the uint32_t type. Since struct types are also, well, types, you can create aliases for struct types:

typedef struct MyStruct {
    [...]
} AliasForMyStruct;

This code declares the struct type and creates the alias type for it in the same breath. (Note that when you typedef, you cannot also declare an instance of the type in the same breath =)). So now I can use AliasForMyStruct instead of the wordy struct MyStruct. So for example, I can declare an instance of the struct MyStruct type by just saying:

AliasForMyStruct instanceOfMyStruct;

instead of doing:

struct MyStruct instanceOfMyStruct;

And I can also make an even more useful alias:

typedef struct MyStruct {
    [...]
} * AliasForMyStruct;

This code creates the type alias AliasForMyStruct that represents a pointer to a struct MyStruct.