Dear
My code is quite complex so it is not possible to put it here and explain every thing.
Why generally the values in the some arrays get changed through coding while I have not did that manually?
Any possible reasons?
Regards
Try to utilize the const keyword whenever possible.
For example, when you pass an array to a function that should not modify the array, use const like this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
void doNotChangeArray(constint array[], int size) {
array[0] = 4; // Error - attempting to modify const parameter
int localVar = array[0]; // Acceptable - this is read-only
}
int main()
{
int array[3] = {1, 2, 3};
doNotChangeArray(array, 3);
std::cout << array[0];
return 0;
}
When you have an array as a member variable of a class, you can again use the const keyword to mark a member function as non-mutator, so that function cannot modify the array.