Let's say you pass the array int A[] = { 1, 2, 3, 4 };
and that the int n is iqual to the number of elements in the array,
in this case 3 since starts at element 0.
This sorting function is going to do the following:
the for loop will start with a 1 as an indexer.
For loop checks that 1 is less or iqual to n, which has a value of 3 (four elements in the array). Is 1 <= 3?. Yes.
The block that belongs to the for loop is executed.
The while loop checks: Is it true that what A[1] (whatever value is in A[1],second element of the array; this case a 2) is not 1?. 2 != 1?. Yes.
The block belonging to the while loop is execute.
variable t gets the value of A[1] which is 2; A[1] gets A[t] which is 3 now, since
A[t] is A[2] or third array element; A[t](or A[2]) gets whatever is in t, at this time a 2.
Then while loop is finished in this round, and for loop increments n by one, making it this time a 2.
So far then we have after this round:
A[0] = 1 (the function loops will never touch this element, as is written)
A[1] = 3
A[2] = 2
A[3] = 4
Do we want to go another round with it. What the heck, let's do it, since I believe
here is were it will get interesting.
Is 2 <= 3?. Yes. Keep going down.
Is A[2] not 2?. Or Is 2 not 2?. No.
The swapping will not start this round. Nothing changes and the for loop will increase n to 3, and gets at it once more. I am too tired thinking what is going to happen.
I hope you get the idea. Is that what you intended to happen?. Doubtful.
Check the logic to make it work with any numbers that get passed as paramenters in the function.
* May I suggest also that you work in a better spacing and indenting in your code. Here's a great link for formatting c/c++ code. This one will help you to post code correctly.
By the way, in the function, this part:
int[]A
Should be: int A[]