#include <stdio.h>
int main(int argc, char **argv) { puts("Hello world!"); }
---
I just wrote this small program. It is sufficiently complex (IMO) to qualify for automatic copyright protection. I wrote it from scratch, so that copyright is mine.
I am entirely sure that this exact code has been written by many others many times in the past. I may have even looked at their code. However, because I just wrote *this* program from scratch and without copying or even consulting someone else's, I hold the copyright to it. On the same matter, I am also not infringing on anyone else's copyright.
Whether I can prove this in court or not is an unrelated question. If sued over this particular piece of code, no doubt I could call many witnesses from the industry who would state that the code could very probably be an original work of mine and not copied. While this might not be the case for most code, it could very well be claimed for code which has only one possible or reasonable implementation, such as certain parts of device drivers or workarounds for bugs.