+ 8

What is the difference between this two declarations

struct p{ int x,y; }; and struct { int x,y; } p;

18th Feb 2019, 7:23 PM
ABADA S
ABADA S - avatar
7 ответов
+ 4
The first declare a struct with name p. The second declare a variable p than refer to an unamed struct
18th Feb 2019, 7:37 PM
KrOW
KrOW - avatar
+ 6
so I can not declare an instance of p in second example How can I use the second way ?
18th Feb 2019, 9:27 PM
ABADA S
ABADA S - avatar
+ 6
I got it thanks master KrOW Soo it is just an instance of unnamed struct
19th Feb 2019, 4:51 PM
ABADA S
ABADA S - avatar
+ 4
What is the benefit of unnamed struct or how I can write a fucntion that returns an instance of unnamed struct
19th Feb 2019, 4:54 PM
ABADA S
ABADA S - avatar
+ 4
What is exactly happening when I write "typedef" befor unnamed struct Why The address of unnamed struct was just in digits Thanks for help
19th Feb 2019, 5:03 PM
ABADA S
ABADA S - avatar
+ 3
No because p is not a struct but it will be yet an instance of an unamed struct (eg you can access to members like p.x or p.y)
18th Feb 2019, 9:39 PM
KrOW
KrOW - avatar