What will the licence of the code be? If this is jurisdiction / country based what is relevant in this case? The place of origin of the poster, the host where the code lives, or the one who tries to view and reuse the unlicensed code?
In that case copyright applies. In most countries, certainly in Europe, this is an automatic process: you publish something, and even without you adding the copyright symbol, you get the copyright.
Software is no different than literature. As a developer, you are considered being the author of your work. When you publish, you are the copyright owner. Copyright law allows an author to prohibit others from reproducing, adapting, or distributing copies of the author's work. In spite of the fact that people can read your source code, your code isn't "free, open source software"!
In short: if you don't add any license information, your code is protected, but make sure you add your name and document when you wrote/published it.
I am not a lawyer, but I have faced a situation where a code contribution was done publicly and anonymously. I did a huge effort to track down the author (and documented my search), but I couldn't find the contributor. The lawyer told me that, in that case, it was safe to assume that the code was in the public domain, as there was nobody to claim ownership (even after me asking the author to make himself public in a comment section). It's always safe to consult a lawyer in cases like this. And document! document! document!
Update based on a comment:
So it doesn't matter on what site it's published?
Yes, it does. When you register on a site, when you publish something on a site, you agree with the terms of agreement of that site.
Some of these terms may not be legal in the country where you reside, in which case the terms are void. For instance: a site can claim that it owns the IP of every picture you upload. In some European countries, companies such as Facebook risk litigation if they do so, because that term is considered illegal.
However, you should take into account that the terms and agreements can be valid, because the internet doesn't have any borders and you can't assume that people in other countries know what the law says in the country you live in.
There was another question that explains what happens if you post code on StackOverflow: Can I copy-paste a snippet from StackOverflow into my GNU-GPL project?
When you post code or an answer on StackOverflow, every one is free to use it, provided that the rules are obeyed. For instance: I wrote a book The Best iText Questions on StackOverflow which bundles questions and answers that were posted on StackOverflow. I can do so, because I allow people to redistribute the content and I give credit to the people who wrote the questions and answers (actually, I am the author of most of the answers).
This is taken from the Terms of Service:
In the event that You post or otherwise use Subscriber Content outside of the Network or Services, with the exception of content entirely created by You, You agree that You will follow the attribution rules of the Creative Commons Attribution Share Alike license as follows:
- You will ensure that any such use of Subscriber Content visually displays or otherwise indicates the source of the Subscriber Content as coming from the Stack Exchange Network. This requirement is satisfied with a discreet text blurb, or some other unobtrusive but clear visual indication.
- You will ensure that any such Internet use of Subscriber Content includes a hyperlink directly to the original question on the source site on the Network (e.g., https://stackoverflow.com/questions/12345)
- You will ensure that any such use of Subscriber Content visually display or otherwise clearly indicate the author names for every question and answer so used.
If you look at my book, you'll see that there's a link to the full question on StackOverflow under every question, as well as a link to the profile of the person who posted the question. I didn't provide such a link for the answers in case I am the author of the answer, because I have the choice to do with my own content what I want. However, I can't prevent that a third party takes my answer and copies it (that wouldn't be fair, but it has happened before and there's very little one can do about it).
If you share code without any license declaration, the general assumption is you apply normal copyrights. That means copying it, modifying it or anything else might be risky. A court may judge, that the way you shared it implied some usage, but to depend on that is highly risky.
And code without clear license declaration isn't open source.
Your code will be unlicensed and no one would be allowed to use it. However, by posting it on services like GitHub, you are granting them [non-exclusive, permanent, irrevocable, unlimited] rights to publish your content in connection with the service. Unless the terms of the service requires otherwise and you accepted, you will retain copyright over the content and reserve all other rights.