Today we will talk about one-dimensional arrays in C language!

Let’s talk about one-dimensional arrays today!
In the C language, the array is a structured data type. According to the different data elements in the array, the array can be divided into numeric array, character array, pointer array, and structure array. It can be seen from this that the elements in the array are elements of the same type.
Array: A sequence composed of data of the same type is an ordered collection. (Note: The ordered set here is not the order of value element size)
One-dimensional array definition:
type specifier array name [constant expression]
For example:
int a [5]
int means this is an integer array; a means The array name of this integer array is a. You can use the name of the array as you like, of course, to facilitate programming and understanding; 5 means there are 5 elements in this integer array.
When defining an array, it is allowed to specify in the same type, such as:
int a, c, f, k1[5], k2[20];
(Or explain, here is the definition of two integer arrays, the first array There are 5 elements in k1, and there are 20 elements in the second array k2)
Assignment of the array:
Just look at the example!
int a [5]={1,2,4,70,5};
int b[10]={90,30,67);
Pay attention to when assigning values: you can assign a value to every element, such as the first array ; You can also assign values ​​to some elements, such as the second array, and the rest of the elements are assigned a value of 0 by default. It must be noted that the number of assigned elements must not exceed the number of elements in the array, such as int c[2]={7, 3,5}; is wrong, because there are only 2 numbers in the c array, but you assign 3 values, so the system will report an error.
[The subscript of an array always starts from 0, such as the first array, a[0]=1, a[1]=2, a[4]=5]
One-dimensional arrays are quite simple. I also briefly talked about it. If friends who are just getting started do not understand, you can read the introduction of other blogs, or you can watch the video of the turtle at station B. It is very good! ! That's it for today!
Happy everyday!

Guess you like

Origin blog.csdn.net/qq_46216951/article/details/108854864