user19628924
user19628924

Reputation:

Does the socket automatically closed after the function finishes

If i had a function that opens a socket and do something with it after the function finishes the socket will be closed? Known that after the function finishes all variables will be destroyed

Upvotes: 0

Views: 156

Answers (1)

tadman
tadman

Reputation: 211720

In C the variables aren't "destroyed", they just fall out of scope and effectively cease to exist. This isn't C++, there are no destructors, RAII isn't a thing that happens automatically.

If you open something, you are responsible for closing it, just as if you allocate memory, you're responsible for freeing it.

Any allocation of any kind comes with responsibility.

Upvotes: 1

Related Questions