I have used a reference in this code for map<int ,int> but when I don't use a reference, the map does not get filled recursively. I have already solved this problem but don't know why I need to use a reference when I already provided map<int ,int> as parameter. Can you illustrate in depth?
void util(Node* root,map<int,int> &m, int level) {
    if (!root) return;
    m[level]+=root->data;
    util(root->right,m,level);
    util(root->left,m,level+1);
}
void diagonalSum(Node* root) {
    map<int,int> m;
    util(root,m,0);
    // cout<<m.size();
    for(auto i=m.begin();i!=m.end();i++){
        cout<<i->second<<" ";
    }
    cout<<"\n";
}
 
     
    