int main()
{
//正确写法
//int ages['A'] = {10, 11, 12, 14, 16};
//int size = sizeof(ages);
//printf("%d\n",size);
//正确写法
/*
int count = 5;
int ages[count];
ages[0] = 10;
ages[1] = 11;
ages[2] = 18;
*/
//printf();
//错误写法
//如果想在定义数组的同时进行初始化,数组元素个数必须是常量,或者不写
//int ages [count] = {10, 11, 12};
int ages[] = {10, 11, 12, 78};
int count = sizeof(ages)/sizeof(int);
for (int i = 0; i<5; i++)
{
printf("ages[%d]=%d\n",i, ages[i]);
}
return 0;
}
//数组的基本使用
void arrayUse()
{
//数组的定义格式: 类型 数组名[元素个数];
int ages[5] = {19, 29, 28, 27, 26};
ages[1] = 29;
/*
ages[0] = 19;
ages[1] = 29;
ages[2] = 28;
ages[3] = 27;
ages[4] = 26;
*/
//遍历:按顺序查看数组的每一个元素
for (int i = 0; i<5; i++)
{
printf("ages[%d]=%d\n",i,ages[i]);
}
}
#include <stdio.h>
int main()
{
/*
char cs[5]= {'a', 'A', 'D' 'e', 'f'};
printf("%p\n",cs);
for (int i = 0; i<5; i++){
printf("cs[%d]的地址是:%p\n",&cs[i]);
}*/
double ages[3]= {10, 19, 18};
printf("%p\n", ages);
for (int i = 0; i<3; i++) {
printf("ages[%d]的地址是:%p\n",i,&ages[i])
}
return 0;
}
#include <stdio.h>
//数值作为函数参数,可以省略元素个数
//数组作文函数参数,传递是整个数组的地址,修改函数形参数组元素的值,会影响到外面实参数组
void change(int array[6])
{
printf("array==%p\n",array);
array[0] = 100;
}
void change2(int n)
{
n = 100;
}
int main()
{
int ages[6] = {10, 11, 10, 11, 10, 11};
printf("ages==%p\n",ages);
change(ages);
// change2(ages[0]);
printf("%d\n",ages[0]);
return 0;
}