Question: I'm new to c++ and have a simple program as below

```
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main()
{
 std::map<std::string, double*> testMap;
 std::vector<std::string> v = {"A", "B", "C"};
 for(size_t i=0;i<v.size();++i)
 {
   std::string sym = v[i];
   double* d = testMap[sym];
   if(!d) continue;
   cout << "this";
 }
 for(std::map<std::string, double*>::iterator  itr=testMap.begin();itr!=testMap.end();++itr)
 {
    cout << itr->first << " " << itr->second << std::endl;
 }

 return 0;
}

```

and its O/P is 

```
sh-4.3$ main                                                                                                                                                  
A 0                                                                                                                                                           
B 0                                                                                                                                                           
C 0  

```

My question is why map is creating new elements with null double pointers

Answer: 
This is the expected behavior of [`std::map::operator[]`](http://en.cppreference.com/w/cpp/container/map/operator_at):

> 
> Returns a reference to the value that is mapped to a key equivalent to
>  key, performing an insertion if such key does not already exist. 
> 
> 
> If an insertion is performed, the mapped value is value-initialized
>  (default-constructed for class types, zero-initialized otherwise) and
>  a reference to it is returned.
> 
> 
> 

For `double*`, the zero-initialized value is a null pointer.

You could modify the value inserted by `std::map::operator[]`:

```
testMap[sym] = ...something...;

```

or specify the key and value by `std::map::insert`:

```
testMap.insert({sym, ...something...});

```
That is the way maps works.
The map must be check if the key is all raedy containt.
Use find(key) for that. In your excample testMap[sym]; creates a new entry.

```
std::map<std::string,double*>::iterator it;
it = testMap.find("A");
if ( it == testMap.end() )
{ // create a new entry
   testMap["A"] = new double(1.0);
}

```

Match fun
Hilko