Q:

c++ max choosing sort

I have started to learn c++. (I learn applied maths at school) And I must learn programming. I have just wrote a max choosing sort in c++. It should print the elements of a predefined array in decreasing order, but it is not working. Can you tell me where did I go wrong?
int* max(int *array)
{
    int *max = array++;
    while(*array)
    {
    if (*max<*array) *max = *array;
    array++;
    }
    return max;
}

void change (int *what, int *to)
{
int *temp = what;
what =to;
to = temp;
}

void sort(int *array)
{
while(*array) change(array,max(array));
array++;
}

int _tmain(int argc, _TCHAR* argv[])
{
    int A[] ={7,5,6,9,2,5,3,1,4,10,6,7,2,8};

    sort (A);
    int i =0;
    while (A[i]) cout<<A[i++];

    getchar();
    return 0;
}

A:

The first problem I see is that while (*array) { ... } won't terminate where you want it to because what is beyond the last element of your array is not certain to be 0 or NULL, or it may terminate in the middle of your array if you are sorting an array that includes 0.
Instead you want to say something like:
int A[] = { ... };
int element_count = sizeof(a)/sizeof(a[0]);
for (int i = 0; i < element_count; ++i) { ... }

