Can you guys please help me understand when to use const?
For example, if I have the following functions:
viod add (int* array)
{
int total = array[1] + array[2];
}
viod subtract (int* array);
viod times (int* array);
viod divide (int* array);
viod printArray(int* array);
and I only intend to use the pointer to read from the dataset and not change any original values in the dataset. I understand that pointers can be used as pass by reference. So would it be a better programming practice to do the following?
viod add (const int* array);
viod subtract (const int* array);
viod times (const int* array);
viod divide (const int* array);
viod printArray(const int* array);
but I don't see people use const this way, adding const everywhere they can, let alone const pointers. Is there a reason for it?
Thanks for answering!