part1:数组数据结构
#includeconst int N=5;int main() { int a[N] = { 1, 2, 3, 4, 5}; int i; for(i=0; i
四个字节
改为char
#includeconst int N=5;int main() { char a[5] = { 'h','e','l','l','o'}; int i; for(i=0; i
1个字节
改为double
#includeconst int N=5;int main() { double a[5] = { 1.0,2.0,3.0,4.0,5.0}; int i; for(i=0; i
八个字节
所以可以看到无论何类型,都是连续的
part2:一维数组的定义,初始化以及数组元素的引用方法
#includeint main() { int a[5]; a[0] = 1; a[1] = 9; a[2] = 8; a[3] = 6; a[4] = 0; printf("a[0] = %d\n", a[0]); printf("a[1] = %d\n", a[1]); printf("a[2] = %d\n", a[2]); printf("a[3] = %d\n", a[3]); printf("a[4] = %d\n", a[4]); return 0;}
#includeint main() { int a[5] = { 1, 9, 8, 6, 0}; int i; for(i=0; i<5; i++) printf("a[%d] = %d\n", i, a[i]); return 0;}
#includeint main() { int a[] = { 1, 9, 8, 6, 0}; int i,n; n = sizeof(a) / sizeof(a[0]); for(i=0; i
#includeint main(){ int a[5] = { 1, 9}; int i; for(i=0; i<5; i++) printf("a[%d] = %d\n", i, a[i]); return 0;}
part3:数组作为函数参数
#includeconst int N=5;int main() { int score[N] = { 99, 82, 88, 97, 85}; int i for(i=0; i
#includeconst int N=5; void init(int a[],int n, int value); int main() { int b[N],i; init(b,N,-1); for(i=0;i
f
#includeconst int N=5;void bubbleSort( int [], int); int main() { int i,a[N]; printf("请输入%d个整型数据: \n", N); for(i=0; i x[j+1] ) { t = x[j]; x[j] = x[j+1]; x[j+1] = t; } } }}
r
#includeint findMax(int a[], int n); const int N=5;int main() { int a[N]; int max, i; printf("输入%d个整数: \n", N); for(i=0;i m) m=a[i]} return m;}
k
#includeconst int N=4;void output(char x[], int n);void rank(char x[]);int main() { char string[N] = { '2','0','1','9'}; int i; printf("排序前: \n"); output(string, N); rank(string); printf("\n排序后: \n"); output(string, N); printf("\n"); return 0; } void output(char x[], int n) { int i; for(i=0; i