有人可以用结构解释这段代码吗?(试图学习Winsock 2)

Ale*_*x G 2 c++ struct

我经常看到形式的结构

struct Employee {
int age;
char* name;
}
Run Code Online (Sandbox Code Playgroud)

我正在为Winsock 2看微软的"入门",看到了这个:

struct addrinfo *result = NULL,
                    *ptr = NULL,
                    hints;

ZeroMemory( &hints, sizeof(hints) );
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
Run Code Online (Sandbox Code Playgroud)

这是什么结构?我的数字结构的名字addrinfo,但后来是什么类型的*result,*ptrhints

另外,如果之前从未编码过,该如何hints给出.ai_family/socktype/protocol

And*_*dyG 7

它是一种C风格的方式,将变量声明为结构的一个实例.addrinfo是在别处定义的结构,result是指向一个实例的指针.这是addrinfo的实际定义

在现代C++中,以下内容是等效的:

addrinfo* result = NULL; // nullptr in C++11 and beyond
addrinfo* ptr = NULL; // nullptr in C++11 and beyond
addrinfo  hints;
Run Code Online (Sandbox Code Playgroud)