First Code : -
Code:
#include<iostream>
using namespace std;
int main()
{
int i = 10;
const int &j = i;
}
how can i create a reference to a const, even when the variable of which the reference i am creating is not const. and thats where my problem starts
Second Code :-
Code:
#include<iostream>
using namespace std;
int main()
{
int i = 10;
const int &j = i;
cout<<i<<j;
j = 20;
cout<<i<<j;
getchar();
}
now, i get error at j=20
Third Code:-
Code:
#include<iostream>
using namespace std;
int main()
{
int i = 10;
const int &j = i;
cout<<i<<j;
i = 20;
cout<<i<<j;
getchar();
}
and this is working
please i need explaination!