title: C Compare Array Elements in Function
body: <p>This is probably going to be a pretty basic question but I'm confused on how to implement something like this.</p>
  
  <p>For a class I'm taking on C I need to take two arrays that can vary in length and compare their elements in a separate function.  (This function only takes the arrays as parameters, not their sizes)  Any element that is in both arrays I need to put into another array and return that array (NOTE: each array is like a set in that no elements repeat in the same array).  I have looked into how I would implement this a little bit and here are some of the issues I'm running into.</p>
  
  <ol>
  <li><p>How do I know where the end of the array is?</p>
  
  <p>I think I saw that I might be able to do {0} as an element in the array for a null element.  If this is true I don't know what I would compare this element to in order to check for null.</p></li>
  <li><p>I think I'm supposed to pass pointers to the first element of the array because I don't think C will let the values of an array be passed, but a little unsure.</p>
  
  <p>If I do pass the arrays as pointers, how can I access the arrays elements to get their data?</p></li>
  <li><p>When returning the array to the main function, how can I return the resulting function without the memory being cleared up?</p>
  
  <p>Should I make the resulting array global, or is there a better way of handling it?</p></li>
  </ol>
  
  <p>Thanks in advance.</p>