Bloomberg LP Interview Question
Software Engineer / DevelopersYes. Use a constant reference.
int i=10;
const int &b=i;
b=20;
printf("%d",b);
// gives an error that the value of i cannot be modified.
No that doesn't seem right.
It is true you cant modify the value of b, but you can change the value of i, which indirectly changed the value of b, therefor it is not a const..
@Richak,
Reference is always constant :).
there is no such thing as constant reference !!!!!!
yes, by declaring them as const.
- AK August 01, 2010ex:
extern const int var1;
Here you are only declaring and not reserving memory on initializing.