I have the following example:
#include <stdio.h>
#include <map>
#include <conio.h>
typedef std::map<int,int> mi;
typedef std::map<int,int>::iterator mit;
mit myfind(mi mymap)
{
    mit it = mymap.find(1);
    printf("in function: %d\n",it->second);
    return it;
}
void main()
{
    mi a;
    a.insert(std::pair<int,int>(1,2));
    a.insert(std::pair<int,int>(3,4));
    mit it = myfind(a);
    printf("out of function: %d\n",it->second);
    _getch();
}
The output is:
in function: 2
out of function: -17891602
Why? Does the iterator become invalid? Why? Thanks in advance.
 
     
     
    