I. Functions of Arrays:
I started learning arrays after lunch! Hey! I eat "skews of incense" at noon ". This is a very common snack in Chengdu! However, most people choose to eat at night. "Stringy incense" is a bamboo sign wearing a few similar foods, such as five diced beef, four potatoes, and so on. Then cook in a pot with special spices. Good food! When I learned the array, I suddenly felt that the array was "a string of incense! A few potato skews are on one bamboo, so I can say that I want this potato! I don't need to say that I want this potato, this potato, and this potato. In this case! I don't need to declare it so many times. Just say a string. Haha!
2. array definition:
Type specifier array name [number of elements]
Potato skews A [100]
3. array features
Each potato is serialized on a bamboo. In addition, one potato you eat has a mark (subscript) 0. The second potato you eat has a note (subscript) of 1, and then goes on in turn! Why should we use 0 for the 1st potato subscripts, because the array name is the first address of the array!
When the array name is used as a function parameter, the first 4-byte address of the array is passed in the past. Therefore, only the first 4-byte address can be written in the copy of the array name parameter. Because the address is passed, you can modify the value of the original array! For example:
# Include void change (int x []) {int temp = x [0]; x [0] = x [1]; x [1] = temp; printf ("the size of the array name is: % d", sizeof (x);} int main (void) {int a [2] = {11, 22 }; printf ("the array elements before the swap are: % d", a [0], a [1]); change (); printf ("the exchanged array element is: % d", a [0], a [1]); printf ("the size of the array name is: % d ", sizeof (a); return (0 );} /*************************************** * ****** the output result is: the size of the array element before the SWAp is: 11 22 the size of the array name is: 4 the size of the array element after the SWAp is: 22 11 the size of the array name is: 8 *************************************** ********/
4. Notes for Arrays:
1: [] the values in the brackets must be fixed, because the boss (compiler) does not know how many potatoes you need. She knows how to keep your account! (I understand this for the moment !, I may feel that my current understanding is wrong in the future! Hey hey !);
2: You can eat (reference) only one potato at a time. You cannot say that I want to eat this string.
3: the C language array can be accessed out of bounds! That is to say, when there are only five potatoes in a string, you can eat six or 6th potatoes, and you can eat the air or other things, but you can think of it as a potato, haha! For example:
V. array addressing formula:
A [n] = a + sizeof (type) * n
Vi. Two-dimensional array:
The two-dimensional array is the same as the one-dimensional array, but each element of the Two-dimensional array is a one-dimensional array. In the memory, it feels like a bamboo sign, which is equivalent to connecting the first and end of two strings of "string incense" into a string. Hey!
It took 5 hours to study the array. I am playing the guitar. Do you like it? After playing for a while, continue to cheer! I tried to write a program within hours (in fact, I am really a child who just learned programming for a few days. I think the misunderstanding is that you didn't choose a good learning material at the time. "Learn with no purpose" may make people concentrate more on exploring the essence of food, because I think a lot of thinking needs to be done in a happy state! Once you have a desire! Thinking is limited. At least in music )!