title: Facing some problem in 2D array to add each row-wise elements in c++
body: <p>In c++, I wrote a code for 2d array to add each row-wise elements. But I don't understand why I got sum=3 in row 5 and 6 where I would get the sum = 2 instead of 3.but in my code others row gave the correct results. I don't know where is the problem?</p>
  <pre><code>    #include&lt;iostream&gt;
      using namespace std;
      
      int main(){
      
      int a[8][4]={{1,1,0,0},{0,1,0,0},{0,0,0,0},{0,0,0,0},{0,1,1,0},{0,1,1,0},{0,0,1,0},{0,0,1,0}};
      
         for(int i=0;i&lt;8;i++){
              for(int j=0;j&lt;4;j++){
                  cout&lt;&lt;a[i][j]&lt;&lt;&quot;  &quot;;
              }
              cout&lt;&lt;endl;
             }
      
         cout&lt;&lt;endl&lt;&lt;endl;
      
      
         int a_row[4]={0};
      
      
         cout&lt;&lt;endl;
      
         for(int i=0;i&lt;8;i++)
         {
             for(int j=0;j&lt;4;j++)
             {
      
      
              a_row[i]=a_row[i]+a[i][j];
      
      
      
             }
             cout&lt;&lt;&quot;Row&quot;&lt;&lt;i+1&lt;&lt;&quot;:  &quot;&lt;&lt;a_row[i]&lt;&lt;endl;
      
      
      
      
         }
      
      
      
      
      
      return 0;
      }
  </code></pre>
  <p>and the output i got-<a href="https://i.stack.imgur.com/D9qEC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D9qEC.png" alt="enter image description here" /></a></p>