C language system learning 4 array

array

1. Creation and initialization of one-dimensional
arrays Creation of arrays
Array: A collection of elements of the same type. Array creation:

type_t arr_name [cost_n]
//tepe_t 数组的元素类型,类似与定义变量
//cost_n 一个常量表达式,用来指定数组的大小 不能使用变量
//name 这个数组的名称

Array initialization
Array initialization refers to giving some reasonable initial values ​​(initialization) to the contents of the array while creating the array

int a1[10]={1,2,3};
int a2[]={1,3,2};
int a3[4]={1,2,3,4};
char a4[]={'a',21,'c'};
char a5[]={'a','b','c'};
char a6[]="hello";

If the array is created without specifying the definite size of the array, it must be initialized. The number of elements in the array is determined according to the initialization content.
Second, the use of one-dimensional arrays
use the [] operator more

#include<stdio.h>  
#pragma warning(disable:4996);

int main()
{
	int a[10],max=0;
	for (int i=0;i<10;i++)
	{
		scanf("%d", &a[i]);
	}
	for (int i = 0;i < 10;i++)
	{
		if (a[i] > max)
		{
			max=a[i];
		}
	}
	printf("十个数中最大值是%d",max);
}

1. Arrays are accessed using subscripts, which start from "0". Be careful when programming.
2. The size of the array can be obtained by calculation.

int  a[10];
int a_size =size(arr)/sizeof(a[0]);

3. The storage of one-dimensional array in memory
can be verified by writing the address and printing it out

Conclusion: With the increase of the array subscript, the address of the element is incremented regularly. Arrays are stored contiguously in memoryinsert image description here

Guess you like

Origin blog.csdn.net/qq_45742383/article/details/113665147