void select(int arr[10])
{
int i,j,min,idx,tp;
for(i=0;i<10-1;i++)
{
min=INT_MAX;
idx = -1;
for(j=i;j<10;j++)
{
if(min>=arr[j])
{
min = arr[j];
idx =j;
}
}
tp = arr[i];
arr[i] = arr[idx];
arr[idx] = tp;
}
}
int main()
{
int arr[10]={5,3,2,2,0,1,3,4,6,8};
int i;
select(arr);
for(i=0;i<10;i++)
printf("%d ",arr[i]);
printf("\n");
return 0;
}
2019年7月18日 星期四
2019年7月13日 星期六
C 常數指標筆記
pointer to variable can not be modified, but pointer can be modified.
int a=1;
int b=3;
int const *p=&a;
const int *p2=&a;
*p=2; // failed
*p2=2; // failed
p=&b; // success
p2=&b; //success
pointer to variable can be modified, but pointer can not be modified.
int a=1;
int b=3;
int *const p=&a;
*p=2; // success
p=&b; // failed
pointer to variable can not be modified, and pointer can not be modified.
int a=1;
int b=3;
const int *const p=&a;
*p=2; // failed
p=&b; // failed
int a=1;
int b=3;
int const *p=&a;
const int *p2=&a;
*p=2; // failed
*p2=2; // failed
p=&b; // success
p2=&b; //success
pointer to variable can be modified, but pointer can not be modified.
int a=1;
int b=3;
int *const p=&a;
*p=2; // success
p=&b; // failed
pointer to variable can not be modified, and pointer can not be modified.
int a=1;
int b=3;
const int *const p=&a;
*p=2; // failed
p=&b; // failed
訂閱:
文章 (Atom)