I am confused at the output of the following code
#include <iostream>
using namespace std;
int main()
{
int i;
double d;
int r=i;
double s=d;
i=5;
cout<<"value of i:"<<i<<endl;
cout<<"value of i reference:"<<r<<endl;
d=11.7;
cout<<"value of d:"<<d<<endl;
cout<<"value of d reference:"<<s<<endl;
cin.ignore();
return 0;
}
the output is as follows value of i: 5 value of i reference : 4370436 value of d: 11.7 value of d reference: 1.78734e-307
I actually don't know why the value of i reference and d reference are like that. I know if I add "&" to the definitions of i and d references, then it will work as references. But I guess I dont fully understand the meaning of reference. Could anyone explain why in this code the output is like that. Thanks a lot!