I'm working with the bubble sort to sort the values in my array into ascending order. There is something I noticed while trying different things to get the code to compile. Initially I wrote my program like this:
Code:
void sortArray(int values[], int sizeofArray);

int main()
{
    int arraySize = 8;
	int numbers[arraySize] = {7, 58, 3, 42, 81, 6, 23, 37};

	cout << "Array values in original order: ";

	for(int i = 0; i < arraySize; i++)
		cout << numbers[i] << " ";

	sortArray(numbers, arraySize);

	getch();
	return 0;
}
But the code would not compile. The compiler complained telling me a constant expression was required. Then I placed the keyword const in front of int arraySize like this:
Code:
void sortArray(int values[], int sizeofArray);

int main()
{
	const int arraySize = 8;
	int numbers[arraySize] = {7, 58, 3, 42, 81, 6, 23, 37};

	cout << "Array values in original order: ";

	for(int i = 0; i < arraySize; i++)
		cout << numbers[i] << " ";

	sortArray(numbers, arraySize);

	getch();
	return 0;
}
Now the program compiles fine. I don't quite understand why the keyword const is required.