can you please help me to understand what a key and value in a map refer to with example
and what dose the below codes mean or imply
int arr[n]
unordered_map<int,int>m
m[a[i]]++; // can you please explain this insertion //
//technique.
//another technique
int x;
while(n–){
cin>>x;
m[x]++, //how is this a hashmap oor a map
}
Hey @adarshsingh2k
So what is key value pair
Say we want to say that ‘abxb’ means 1
‘cjjwj’ means 2 and some othe pairs like this
So we want to map some string to some no
This is where hashmap comes into picture and we use them to do the same.ie mapping of some datatype to some other data type
Another example can be ascii values
Each char have a corresponding ascii value
That can be done using hashmaps as well
So talking about ur code segment
When key is not in map already then its default value is 0 (for int value type)
So in the above line we are simply incrementing the value corresponding to the key a[i] by 1
Again here we are doing the same we are incrementing value corresponding to key x by 1
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.