I have problem in understanding the meaning of constant variables. As far as I know, constant variables can not be modified in the scope.But in the example below:
double interval ( const double t, const double x, const double y, const double z)
{
function code
}
int main()
{
double t(0) , x(0) ,y(0) ,z(0)
std::cin>> t;
std::cin>>x ,y,z;
double s= interval (t,x,y,z);
//the rest of the code
}
I don't understand why in th example above they first initialized to zero and then the code asks for inputs for these variables.....If they are supposed to be constant they should't changed from 0
double interval ( constdouble t, constdouble x, constdouble y, constdouble z)
{
// function code
}
int main()
{
double t(0) , x(0) ,y(0) ,z(0)
std::cin>> t;
std::cin>>x ,y,z;
double s= interval (t,x,y,z);
//the rest of the code
}
on Lines 9, 10, before they reach Line 11, t, x, y, z are being modified by input from cin!!!
those const just mean in Line 3, t, x, y, z cannot be modified
Line 8, I am pretty sure that says "double" and not "const double". Line 10, that is incorrect, it is only going to input to z because of how the comma operator works. Replace the commas with >>. (eg cin >> x >> y >> z;)