title: Why uninitialized char array is filled with random symbols?
body: <p>I have a this fragment of code in <strong>C++</strong>:</p>
  
  <pre><code>char x[50];
  cout &lt;&lt; x &lt;&lt; endl;
  </code></pre>
  
  <p>which outputs some random symbols as seen here:
  <a href="https://i.stack.imgur.com/bnHK4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bnHK4.png" alt="enter image description here"></a></p>
  
  <p>So my first question: what is the reason behind this output? Shouldn't it be spaces or at least same symbols?</p>
  
  <p>The reason I am concerned with this is that I am writing program in CUDA and I'm doing some character manipulations inside <code>__global__</code> function, hence the use of <code>string</code> gives a "calling host function is not allowed" error.
  But if I am using "big enough" char array (each chunk of text I am operating with differs in size, meaning that it will not always utilize char array fully) it's sometimes not fully filled and I left with junk like in the picture below hanging at the end of text:</p>
  
  <p><a href="https://i.stack.imgur.com/yzayX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yzayX.png" alt="enter image description here"></a></p>
  
  <p>So my second question: is there any way to avoid this?</p>