title: Only one element of array is being passed into function. C++
body: <p>For some reason, my function <code>LinearSearch</code> is only getting the first element of the array that's being passed in. I found this by putting a breakpoint in the function and looking at the locals that it has, and I don't know why it's only getting the <code>7</code> from the array <code>a</code>. The test case I have is the following (GoogleTest):</p>
  
  <pre><code>TEST(LinearSearch, ElementExists2Items) {
    // LinearSearch should return a pointer to the item if it exists in the array.
    int a[2] = {7, 2};
    EXPECT_EQ(a, LinearSearch(a, 2, 7));
    EXPECT_EQ(a + 1, LinearSearch(a, 2, 2));
  }
  </code></pre>
  
  <p>Here is my <code>LinearSearch</code> function:</p>
  
  <pre><code>int* LinearSearch(int theArray[], int size, int key) {
      if (size == 0)
          return nullptr;
  
      for (int i = 0; i &lt; size; i++) {
          if (key == theArray[i])
              return (theArray);
          else
              return nullptr;
      }
  }
  </code></pre>
  
  <p>Am I missing something? Do I need to pass <code>theArray</code> by reference instead? I don't know why it's only getting the first value passed into the function.</p>