数组倒置:
#include <stdio.h>
void invert(int x[],int n);
void main()
{
int i,*p,a[10]={2,3,4,5,6,7,8,9,10,11};
printf("%s\n","元素倒置前:");
for(p=a;p<a+10;) printf("%d ",*(p)++);
printf("\n");
p=a;
invert(p,10);
printf("%s\n","元素倒置后:");
for(p=a;p<a+10;) printf("%d ",*(p)++);
printf("\n");
}
void invert(int x[],int n)
{
int temp,i,j,m=(n-1)/2;
for (i=0;i<=m;i++)
{
j=n-1-i;
temp=x[i];x[i]=x[j];x[j]=temp;
}
}
void invert(int x[],int n);
void main()
{
int i,*p,a[10]={2,3,4,5,6,7,8,9,10,11};
printf("%s\n","元素倒置前:");
for(p=a;p<a+10;) printf("%d ",*(p)++);
printf("\n");
p=a;
invert(p,10);
printf("%s\n","元素倒置后:");
for(p=a;p<a+10;) printf("%d ",*(p)++);
printf("\n");
}
void invert(int x[],int n)
{
int temp,i,j,m=(n-1)/2;
for (i=0;i<=m;i++)
{
j=n-1-i;
temp=x[i];x[i]=x[j];x[j]=temp;
}
}
void change(int array[],int n){// 参数分别是数组和数组大小(从1开始的)
int i,temp;
for(i=0;i<n/2;i++)
{
temp=array[i];
array[i]=array[n-1-i];
array[n-1-i]=temp;
}
}
int i,temp;
for(i=0;i<n/2;i++)
{
temp=array[i];
array[i]=array[n-1-i];
array[n-1-i]=temp;
}
}
http://zhidao.baidu.com/link?url=bEzpSWF2Gm9b0Le2bNXcvUTDZNpk44n8vug8mpJ1EVzuSzwJeOCPG4pQgLwlnlEynt0S8maMofMzYNBYGfWGeiwnm96t5WVILcqH_qkSqxa
http://zhidao.baidu.com/link?url=6OASO2n2K5bfBliGQd2DSFoAJ_SHql3naZjgFjIgj6avcWX6YwS2dKKQyVgeBagPHOY6tcfekkxv7O_8e6HIG_
int n = 10,a[n]问题:
#include<stdio.h>
#include<string.h>
#include<iostream>
int main()
{
const int n = 20;//正确
int main()
{
const int n = 20;//正确
int n = 20;//错误
int a[n];
}
int a[n];
}