double midpoint(const double &a, const double &b){
/*code*/
}
int main(){
double x=midpoint(1,2);
cout << x << endl;
}
Now in the function argument, I use call by reference. But in call by reference original variable is modified. But here, I use function argument as numbers themselves. Then in which memory space are there values stored?
Also, note that in this case, the code gives an error (invalid initialization of non-const reference of type 'int&' from an rvalue of type 'int').
So what exactly is the functioning of const
part?
double midpoint(double &a, double &b){
/*code*/
}
int main(){
double x=midpoint(1,2);
cout << x << endl;
}