lundi 22 mai 2017

Memory allocation with reference variable in C++

I have compiled following piece of code in G++ compiler, it's working fine without any error or warning.

#include <iostream>             
int main()                      
{                               
    int &r = *(new int(100));   
    std::cout << r << std::endl;
    return 0;                   
}

How does the reference variable working with memory allocation?

Is it valid to allocate memory for reference variable?

Aucun commentaire:

Enregistrer un commentaire