Even if you publish your sourcecode on every advertising billboard in the country, you still (by default, even without a notice) have copyright. Without this, advertisers for example wouldn't have copyright on their adverts.
However, many public places to post source code have implicit terms that you agree to by posting content there. For example, everything you publish on a Stack Exchange site (source code included) is under a Creative Commons license (I forget which one exactly) which basically gives anyone the right to copy that material. I assume anyone who copies it can't claim ownership, but there are sites which basically suck up all the stack exchange content and reproduce it with adverts added, hoping to get the Google traffic - and that's legal.
Also, although you have copyright on all original content you create by default, once you make it easy to copy that material, your rights may be practically lost anyway. After all, if half the internet is copying your material, you can't prosecute them all - and the courts probably don't take your rights very seriously if you clearly haven't.
Usual may-vary-by-country and I'm-not-a-lawyer disclaimers apply.