title: Default value of dynamic bool array in C++
body: <p>I need to create a bool array with an unknown length passed by parameter. So, I have the following code:</p>
  
  <pre><code>void foo (int size) {
  
      bool *boolArray = new bool[size];
  
      for (int i = 0; i &lt; size; i++) {
  
              if (!boolArray[i]) {
  
                  cout &lt;&lt; boolArray[i];
  
              }
      }
  }
  </code></pre>
  
  <p>I thought that a boolean array was initializing with false values...</p>
  
  <p>Then, if I run that code in Eclipse (on Ubuntu), it works fine for me, the function prints all the values because <strong>!boolArray[i]</strong> return true (but the values are not false values, they are garbage values). If I run it in Visual Studio, the values are garbage values too, but the function does not print any value (because <strong>!boolArray[i]</strong> returns false). Why the array values are not false values by default?!? And why <strong>!boolArray[i]</strong> returns false in Visual Studio but it returns true in Eclipse?!?</p>
  
  <p>I read this question: <a href="https://stackoverflow.com/questions/4262914/set-default-value-of-dynamic-array">Set default value of dynamic array</a>, so if I change the code like the following, it works fine for me too (in Eclipse and in Visual Studio)! But I have no idea why.</p>
  
  <pre><code>void foo (int size) {
  
      bool *boolArray = new bool[size]();
  
      for (int i = 0; i &lt; size; i++) {
  
              if (!boolArray[i]) {
  
                  cout &lt;&lt; boolArray[i];
  
              }      
      }
  }
  </code></pre>
  
  <p>Sorry for my bad English!</p>
  
  <p>Thanks in advance!</p>