本人C语言全靠自学,指针函数学的一般,请大神看看,怎么能保证数组a的值不变
void changed(int b[], size_t);
main(void)
{
int a[10] = { 10,3,90,100,90,4,5,1,2,100 };
char *c = &a[0];
changed(c, 10);
for (size_t i = 0;i < 10;++i)
{
printf("%d ", a[i]);
}
return 0;
}
void changed(int b[], size_t count)
{
int ptemp = 0;
for (size_t i = 0;i < count - 1;++i)
{
for (size_t j = i;j < count;++j)
{
if (b[i] > b[j])
{
ptemp = b[i];
b[i] = b[j];
b[j] = ptemp;
}
}
}
for (size_t i = 0;i < count;++i)
{
printf("%d ", b[i]);
}
printf("\n");
}
main(void)
{
int a[10] = { 10,3,90,100,90,4,5,1,2,100 };
char *c = &a[0];
changed(c, 10);
for (size_t i = 0;i < 10;++i)
{
printf("%d ", a[i]);
}
return 0;
}
void changed(int b[], size_t count)
{
int ptemp = 0;
for (size_t i = 0;i < count - 1;++i)
{
for (size_t j = i;j < count;++j)
{
if (b[i] > b[j])
{
ptemp = b[i];
b[i] = b[j];
b[j] = ptemp;
}
}
}
for (size_t i = 0;i < count;++i)
{
printf("%d ", b[i]);
}
printf("\n");
}
数组a排序后按从小到大顺序排列,但是,本身数组a的顺序也被改写了,如何保证数组a的顺序不改变