How can a file contain null bytes?
<p>How is it possible that files can contain null bytes in operating systems written in a language with null-terminating strings (namely, C)?</p>

<p>For example, if I run this shell code:</p>

<pre><code>$ printf "Hello\00, World!" &gt; test.txt
$ xxd test.txt
0000000: 4865 6c6c 6f00 2c20 576f 726c 6421       Hello., World!
</code></pre>

<p>I see a null byte in <code>test.txt</code> (at least in OS X). If C uses null-terminating strings, and OS X is written in C, then how come the file isn't terminated at the null byte, resulting in the file containing <code>Hello</code> instead of <code>Hello\00, World!</code>? Is there a fundamental difference between files and strings?</p>