The problem I believe, appears to stem from your understanding and use of pointers.
Your code
pointer + i
really doesn't make any sense. I'll try to illustrate with a simple diagram.
Imagine you had an array with some data in it. We'll assume that *pointer holds the address of the first element. We'll also assume an arbitrary location in memory of 0x4003000.
| a | b | c | d | \0 |
So,
'a' is at 0x4003000,
'b' is at 0x4003001,
'c' is at 0x4003002,
'd' is at 0x4003003
and the
NULL terminator is at 0x4003004
So, now we have that in place, lets run through the 3 lines from and including your first for loop - assuming size to be 4.
for(i = pointer; i < (pointer+size); ++i){
for(j = pointer + 1; j < (pointer+size); ++j){
if((pointer + i) < (pointer + j)){
This will turn into
for (i=0x4003000; i<0x4003000+4; ++i)
{
for (j=0x4003001; j<0x4003000+4; ++j)
{
if ((0x4003000+0x4003000) < (0x4003000+0x4003001))
Starting to see the problem yet?!
The solution is, I think: (your intention isn't 1000% clear to me)
void sort_ver2(int *pointer, int size)
{
int *i, *j;
int temp;
for(i = pointer; i < (pointer+size); ++i)
{
for(j = pointer + 1; j < (pointer+size); ++j)
{
if( *i < *j)
{
temp = *j;
*j = *i;
*i = temp;
}
}
}
}
I assume you'd like to compare the _values_ that i and j point to, swapping them if a condition is met?
A truly horrid (but perfectly valid & legal) way to use pointers, in my humble opinion. :)