title: Why is this below code giving heap overflow Error by just changing the comparison operator from &&(AND) to ||(OR)?
body: <p>I was trying to solve below problem:
  Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must appear as many times as it shows in both arrays and you may return the result in any order.</p>
  <p>Example 1:
  Input: nums1 = [1,2,2,1], nums2 = [2,2]
  Output: [2,2]</p>
  <p>Here is my code:</p>
  <pre><code>/**
   * Note: The returned array must be malloced, assume caller calls free().
   */
  int* intersect(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize){
      
      for(int i=0; i&lt;nums1Size-1; i++){
          if(nums1[i]&gt;nums1[i+1]){
              int temp = nums1[i];
              nums1[i] = nums1[i+1];
              nums1[i+1] = temp;
              i = -1;
          }
      }
      
      for(int i=0; i&lt;nums2Size-1; i++){
          if(nums2[i]&gt;nums2[i+1]){
              int temp = nums2[i];
              nums2[i] = nums2[i+1];
              nums2[i+1] = temp;
              i = -1;
          }
      }
      
      int i = 0;
      int j = 0;
      int* res = (int*)malloc(10* sizeof(int));
      int k = 0;
      
      if(!(nums1Size &gt; nums2Size)){
          int * temp = nums1;
          nums1 = nums2;
          nums2 = temp;
          int tempint = nums1Size;
          nums1Size = nums2Size;
          nums2Size = tempint;
      }
      
      while(i&lt;nums1Size &amp;&amp; j&lt;nums2Size){
          if(nums1[i] &gt; nums2[j]){
              j++;
          }
          else if(nums1[i] &lt; nums2[j]){
              i++;
          }
          else{
              res[k++] = nums1[i];
              i++; j++;
          }
      }
      *returnSize = sizeof(res)/sizeof(res[0]);
      return res;
  
  }
  </code></pre>