As all other answers have stated, defining a name after a struct definition creates an instance of that struct with that name in whatever scope it was defined. So, struct __bar__ { ... } bar;
is equivalent to struct __bar__ { ... }; __bar__ bar;
. As of writing, however, none of the other answers attempt to answer the second question: "Why not write it in the next line like cpp reference does in its examples?"
The most practical argument I can think of for using this "name after" syntax is when you only need one instance of this struct. This way, it is guaranteed that both the definition and declaration happen in the same place; which is not guaranteed using the "next line" approach. This also has the added benefit of only having one place where the struct is defined, which means if you want to change it at any point you only have to go to 1 spot instead of 2 (potentially disjunct) ones.
This translates well for when you (absolutely) need a single set of data in a global scope:
// 1 bar, in the global scope
struct Bar {
int a;
} global_bar;
int main()
{
// Do something with global bar
global_bar.a = 100;
return 0;
}
Whereas, if you wanted multiples of the struct you would probably tend towards code like:
struct Bar {
int a;
};
int main()
{
// 2 bars, in the local scope
Bar bar_1 = Bar();
Bar bar_2 = Bar();
// Do something with the local bars...
return 0;
}