[Solved] What does struct mean in variable definition? c++


In this statement

struct sockaddr *ai_addr; 

there is used so-called elaborated type specifier. This statement does two things. First of all it declares type name sockaddr and declares a pointer of this type.

To declare a pointer to a structure there is no need that the structure would be defined that is that it would be a complete type because the size of the pointer does not depend on the size of the structure.

For this statement

struct sockaddr ai_addr;

the compiler issues an error because it needs to allocate memory for the object of type struct sockaddrbut it doesn not know the size of the structure because the structure was not yet defined. That is the structure is an incomplete type. It is only declared but not yet defined and its size is unknown.

3

solved What does struct mean in variable definition? c++