title: Array doesn't initialize. Each element contains trash, but not required value
body: <ol>
  <li><p>First problem: 0 errors, 0 warnings. Sure the code is correct. Tell me what is wrong? (This is part of program.) I can't understand what is wrong. At least it will display <code>array[3][3] = {{1,1,1},{1,1,1},{1,1,1}}</code></p></li>
  <li><p>Second problem: But instead of 'zero's I see clear fields. (I see nothing) But if there is <code>{{1,1,1},{1,1,1},{1,1,1}}</code>, I see '1's... Tell me why?</p></li>
  </ol>
  
  <p></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  //#define L 3            /* Including the [0]-element */
  //#define C 3            /* Including the [0]-element */
  #define RANGE 100      /* Set up the range of random values */
  
  int fill_in(int *, int, int); /* Prototype of function */
  
  int main()
  {
     int L = 3, C = 3;
  
     int array[L][C];  // L - Line, C - Column
     int i, j;        // Global variables
  
     int * aPtr;
     aPtr = &amp;array[L][C];
  
     srand((unsigned)time(NULL));
  
     fill_in(aPtr, L - 1, C - 1);
  
     /* Displaying array (AFTER) */   //  &lt;--- going to make a function, but my first one 
     printf("\nAFTER:\n");            //       doesn't work correctly =(
     for (i = 0; i &lt;= L - 1; i++)
     {
        for (j = 0; j &lt;= C - 1; j++)
           printf("%2.d ", array[i][j]);
        printf("\n");
     }
  
     return 0;
  }
  
  int fill_in( int * aptr, int m, int n)   ///  PROBLEM?  O_о
  {
     int arr[m][n];
     int i, j;      // Local variables
  
     /* Filling array with random values */
     for (i = 0; i &lt;= m - 1; i++)
     {
        for (j = 0; j &lt;= n - 1; j++)
           arr[i][j] = 1;      //1 + rand()%RANGE;  // If each element == 1, it works! 
     }
  
     return arr[i][j];
  }
  </code></pre>
  
  <p>UPDATE: 
  I've solved it! 
  Explanations is in comments of the code.
  The following code works properly:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  #define Lines 2            /* Including the [0]-element */
  #define Columns 2            /* Including the [0]-element */
  #define RANGE 100      /* Set up the range of random values */
  
  int fill_in(int*, int, int); /* Prototypes of functions */
  int display(int*, int, int);
  
  int main()
  {
      int L = Lines, C = Columns;
      int array[L][C];  // L - Line, C - Column
      int* aPtr;
      aPtr = &amp;array[0][0];
  
      srand((unsigned)time(NULL));
  
  
      fill_in(aPtr, L, C);   /* Filling array with random values. */
      display(aPtr, L, C);   /* Displaying array. */
  
  
      return 0;
  }
  
  ////////////////////////////////////////////////////////////////////
  
  /**   Eureka!  The fact is that pointer of a[0][0] is *ptr[0], and
        the pointer of a[2][2] is *ptr[8] ---&gt; The 8-th element of the array[2][2].
  
    &gt;&gt;&gt;&gt;   Pointer sees array[][] not as matrix (square), but as a line!
    &gt;&gt;&gt;&gt;   As if to make a line of a square matrix!
  
  */
  
  int fill_in(int* aptr, int m, int n)        /* Filling array with random values. */
  {
     int i;      // Local variables
     int max_number_of_element = ((m+1)*(n+1)-1);
  
     for (i = 0; i &lt;= max_number_of_element; i++)
        *(aptr + i) = 1 + rand()%RANGE;
  
     return *aptr;
  }
  
  
  int display(int* aptr, int m, int n)    /* Displaying array. */
  {
     int i;
     int count = 1;
     int max_number_of_element = ((m+1)*(n+1)-1);
  
     for (i = 0; i &lt;= max_number_of_element; i++)
     {
        printf("%2.d  ", *(aptr + i));
  
        if (count % (n+1) == 0)
           printf("\n");
        count++;
     }
  return i;
  }
  </code></pre>
  
  <p>Instead of:</p>
  
  <pre><code>for (i = 0; i &lt; m; i++)
     for (j = 0; j &lt; n; j++)
        aptr[i * n + j] = 1;
  </code></pre>
  
  <p>I've used:</p>
  
  <pre><code>for (i = 0; i &lt;= max_number_of_element; i++)   
    *(aptr + i) = 1;
  //Pointer sees array[][] not as matrix (square), but as a direct sequence (line).
  </code></pre>
  
  <p>Not sure whether it does anything outside of the array, but the main problem is solved.</p>
  
  <p>P.S.
  Let me know if I was wrong.</p>