title: Understanding 2D Char Array in C
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #define MAX 100
  /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  void sortStrings(char arr[][MAX], int n)
  {
      char temp[MAX];
      int j, i;
      // Sorting strings using bubble sort
      for (j=0; j&lt;n-1; j++)
      {
          for (i=j+1; i&lt;n; i++)
          {
              if (strcmp(arr[j], arr[i]) &gt; 0)
              {
                  strcpy(temp, arr[j]);
                  strcpy(arr[j], arr[i]);
                  strcpy(arr[i], temp);
              }
          }
      }
  }
  int main(int argc, char *argv[]) 
  {       
      char arr[][MAX] = {"GeeksforGeeks","Quiz","Practice","Gblogs","Coding"};
      int n = sizeof(arr)/sizeof(arr[0]);
      int i;
      sortStrings(arr, n);
  
      printf("Strings in sorted order are : ");
      for (i=0; i&lt;n; i++)
          printf("\n String %d is %s", i+1, arr[i]);
  
      return 0;
  }
  </code></pre>
  
  <p>I got this code directly from GeeksForGeeks for Bubble sort "<a href="https://www.geeksforgeeks.org/sorting-strings-using-bubble-sort-2/" rel="nofollow noreferrer">https://www.geeksforgeeks.org/sorting-strings-using-bubble-sort-2/</a>"
  And I'm trying to make sense of it. I understand the basic ideology of how 2D arrays work where the first array is the index, and the second array is the contents of the index. However, I am confused as to what is happening when </p>
  
  <pre><code>if (strcmp(arr[j], arr[i]) &gt; 0)
              {
                  strcpy(temp, arr[j]);
                  strcpy(arr[j], arr[i]);
                  strcpy(arr[i], temp);
              }
  </code></pre>
  
  <p>I don't understand what arr[j] or arr[i] is referring to in arr[][MAX]</p>
  
  <pre><code>printf("\n String %d is %s", i+1, arr[i]);
  </code></pre>
  
  <p>I'm also confused as to what is going on in the print of arr[i] as well. Shouldn't it be identified which index containing which contents is being printed? Sorry if my questions are confusing, I am new to 2D arrays. </p>