# I also want to learn C language-Chapter 9: "string incense"-array

Source: Internet
Author: User
Tags array definition
ArticleDirectory
• I. Functions of Arrays:
• 2. array definition:
• 3. array features
• 4. Notes for Arrays:
• V. array addressing formula:
• Vi. Two-dimensional array:
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 isFirst address of the array!

When the array name is used as a function parameter, what is passed in the past is4-byte first addressTherefore, only the four-byte first address can be recorded 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 <  Stdio. h  >    Void  Change (  Int  X []){  Int  Temp  =  X [  0  ];X [  0  ]  = X [  1  ];X [  1  ]  =  Temp;Printf (  "  Size of array name: % d \ n  "  ,  Sizeof  (X ));}  Int  Main (  Void  ){ Int  A [  2  ]  =  {  11  ,  22  };Printf (  "  The array element before the SWAp is % d \ t % d \ n  "  , [  0  ], [  1 ]);Change ();Printf (  "  The exchanged array element is % d \ t % d \ n.  "  , [  0  ], [  1  ]);Printf (  "  Size of array name: % d \ n  "  ,  Sizeof  ());  Return (  0  );}  /*  **************************************** *****The output result is: the array element before the SWAp is: 11 22.Array name size: 4The elements of the exchanged array are 22 11.Array name size: 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

A [n]: The array element you want to address

A: The first address of the array.

Sizeof (type): element size

N: array subscript

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! Strive to learn to write in hoursProgram(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 the learning materials. "Learn with no purpose" may make people concentrate more on exploring the essence of things, 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 )!

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.