What\'s the usefulness of the function memset()
?.
Definition: Sets the first num bytes of the block of memory pointed by
I guess that serv_addr
is some local or global variable of some struct
type -perhaps struct sockaddr
- (or maybe a class
).
&serv_addr
is taking the address of that variable. It is a valid address, given as first argument to memset
. The second argument to memset
is the byte to be used for filling (zero byte). The last argument to memset
is the size, in bytes, of that memory zone to fill, which is the size of that serv_addr
variable in your example.
So this call to memset
clears a global or local variable serv_addr
containing some struct
.
In practice, the GCC compiler, when it is optimizing, will generate clever code for that, usually unrolling and inlining it (actually, it is often a builtin, so GCC can generate very clever code for it).