
int to char / char to int
how is it that this selection sort code works? the code is written
fine and should work. grades is a char array that is passed into the
routine. my question is grades is an array of CHARACTERS! and this
still works fine. i would expect an error at the line with the "**"
next to it, because i thought that something like this: "MinValue =
grades[Index];" would give you an error if "MinValue" was a int type
(which it is in my program) and "Array" is declared a an array of
characters. doesn't grades[Index] give you the value of that index in
array? which is a character. how/why is that assignment allowed?
when i try it with an array of strings i get the expected error, can
someone explain why i get it with string arrays and not with character
arrays?
int StartScan, MinIndex, MinValue;
cout << "in SelectionSort" <<endl;
for(StartScan = 0; StartScan < (count-1); StartScan++)
{
MinIndex = StartScan;
MinValue = grades[StartScan];
for(int Index = StartScan + 1; Index < count; Index++)
{
if (grades[Index] < MinValue)
{
MinValue = grades[Index]; **
MinIndex = Index;
}
}
grades[MinIndex] = grades[StartScan];
grades[StartScan] = MinValue;
}