title: STL vector usage problem -- Function returning non-zero Iterator
body: <p>I was trying to use the vector STL, where iam facing a weird response from the following sample program :</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  vector&lt;int&gt;::iterator  fun();
    vector&lt;int&gt; myvector;
  
  bool IsOdd (int i) {
    return ((i%2)==1);
  }
  
  int main()
  {
     vector&lt;int&gt;::iterator  it;
  
       it = fun();
  
  if (it == myvector.end() )
  cout &lt;&lt; "Reached end, Global" &lt;&lt; endl;
  else
  cout &lt;&lt; "Not end" &lt;&lt; endl;
  
  
  }
  
  vector&lt;int&gt;::iterator  fun() {
    vector&lt;int&gt;::iterator it;
  
    myvector.push_back(10);
    myvector.push_back(26);
    myvector.push_back(40);
    myvector.push_back(56);
  
    it = find_if (myvector.begin(), myvector.end(), IsOdd);
    cout &lt;&lt; "The first odd value is " &lt;&lt; *it &lt;&lt; endl;
  
  if (it == myvector.end() )
  cout &lt;&lt; "Reached end, inside the function" &lt;&lt; endl;
  else
  cout &lt;&lt; "Not end" &lt;&lt; endl;
  
    return it;
  }
  </code></pre>
  
  <p>Iam getting "Reached End" inside the function fun(), whereas, in the main program, it is showing up as "Not End". </p>
  
  <p>Not sure, what might be the reason. Also, found that, the Address of myvector.end() is showing up as Zero in the main program [ after the fun() call ], where-as, showing a non-zero value inside the function fun().</p>