Reputation:
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
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