title: C - structures and lists
body: <p>I want to save the cartesian product of two arrays into one multidimentional array.</p>
  
  <p><code>arr[number][0]</code> - number from the first array<br>
  <code>arr[number][1]</code> - number from the second array</p>
  
  <p>number = sizeof(array1)*sizeof(array2)</p>
  
  <pre><code>int main() {
      int arr1[4] = {1, 4, 2, 3};
      int arr2[4] = {4, 1, 3, 3};
      int **outcomes = getProduct(arr1, 4, arr2, 4);
  
      int i;
      for(i = 0; i &lt; 16; i++)
          printf("%d", outcomes[i][0]);
  
      getchar();
  }
  
  int* getProduct(int arr1[], int size1, int arr2[], int size2) {
      int **outcomes = (int *)malloc(sizeof(int)*16), count = 0, i, j;
  
      for(i = 0; i &lt; size1; i++) {
          for(j = 0; j &lt; size2; j++) {
              outcomes[count][0] = arr1[i];
              outcomes[count][1] = arr2[j];
              count++;
          }
      }
      return outcomes;
  };
  </code></pre>
  
  <p>However, this code strangly breaks while being in the nested loop inside getProduct() function. The logic is ok, I thing the problem might be with pointers.</p>
  
  <ol>
  <li>Why do I need to initialize multidimentional arrays with two pointers?</li>
  <li>Why isn't this code working?</li>
  <li>Do u have any advices for me on how can I improve this code? ( I didn't code in C too much so I don't know which structures a "good" code uses).</li>
  </ol>