Q:

Do sockets persist between function calls?

In the C language, you have local variables in functions that are destroyed when the function returns (they arn't accessible anymore, unless you pass around pointers obviously).
What happens to sockets? Specifcially, if I create a socket in 1 function, can I pass around the sockid and bind it in another, listen in another, and accept in another?
From what I can see this should work, but I'm not an expert in C.

A:

There should be no problem doing that.  For example:
int sock = my_socket();
my_bind(sock);
my_listen(sock);
int connected_sock = my_connect(sock);
my_read(connected_sock);

