What are bar and x below and why are they located there? Are they instances of the structs?
I was reading this Stackoverflow question whose code I have pasted here and I found that the poster and one of the answers use variable names [bar and x] after the definition of the struct. cpp reference doesn't use this syntax their examples and I don't know what the syntax is called nor what the syntax does to look it up.
If it is just about creating an instance of a struct, why not write it in the next line like cpp reference does in its examples?
struct _bar_
{
int a;
} bar;
struct test {
int value;
} x;
struct test { int value; } x; declares x to be an object of type struct test. It is a simple declaration, the same as int x, with struct test { int value; } in place of int.
In
struct _bar_ {
int a;
} bar;
bar is a declaration of a variable of type struct _bar_.
It's the same as:
struct _bar_ bar;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With