title: Unable to explain the output for the following C++ snippet
body: <pre><code>#include &lt;bits/stdc++.h&gt;
  using namespace std;
  
  int main() {
     int dp[5][6];
     memset(dp,0,sizeof(dp));
     dp[1][0]=0;
     for(int i=1;i&lt;=9;i++){
        dp[1][i]=1;
     }
     cout&lt;&lt;dp[2][0]&lt;&lt;endl;
     cout&lt;&lt;dp[3][0]&lt;&lt;endl;
   }
  </code></pre>
  
  <p>This above snippet produces an unexpected output:</p>
  
  <pre><code>1
  0
  </code></pre>
  
  <p>However when I change the dp array size to dp[100][100], 
  I get the expected output as:</p>
  
  <pre><code>0
  0
  </code></pre>
  
  <p>I tried printing the 2D matrix size as well: </p>
  
  <pre><code>sizeof(dp)/sizeof(int)
  </code></pre>
  
  <p>I am getting the correct values : 30 in case of dp[5][6] and 10000 in case of dp[100][100].
  I compiled and executed the code using a standard g++ compiler in linux.
  Can someone explain to me the cause of this erroneous output.</p>