C struct

Above code works under Ubuntu20.
Can someone please help me to understand the struct variable 'pandora' declaration and initialization issue?

Specifically, the issue is from line3 to line9, what is this declaration style? Any reference would be better.
It seems that I declared a struct variable 'pandora' , and then assigned values to this variable.
I was confused on two variables 'pandora' did not make the gcc complier to issue error.

Many Thanks!

回答

Just found that this doesn't compile:

struct Pandora {
	char *version;
	int status;
} pandora = {"some str", 0};

struct Pandora pandora = { "0.0.5", 4};

then I realized that line3 to line9 may works just like this:

struct Pandora pandora;
struct Pandora pandora = { "0.0.5", 4};

the first pandora appears as a decleration, while the second is as a definition.

以上是C struct的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>