C Quick Start series (4)

Source: Internet
Author: User

C Quick Start series (4)

C Quick Start series (4)


C language Array


--------- Reprinted, please specify the Source: coder-pig

Tip: if you cannot see the image, right-click and save it as needed;

Note that the above Code should be repeated by yourself!


This section introduces:

After learning the previous three series, we have a certain understanding of the C language;

It is not difficult to write such a code:

Enter the scores of the five students, calculate the sum and average value, and print the results!

I believe everyone will first define five variables to store the scores of five students, and then calculate them!

However, if the number of required students is not 5, but 20, 50, or more, do you define a bunch of variables?

This is obviously unwise. In C, we store several data of the same data type in order to a collection!

This kind of set is the array to be learned in this section!


This section describes the road map.





1. One-dimensional array and two-dimensional array:




2. String and String Array





Summary:

① An array is an ordered set of variables of the same data type. Elements in the array can be accessed by subscript.

② Definition, initialization and reference of one-dimensional arrays

③ Two-dimensional arrays are used to store table data, define, initialize, and reference.

④ Distinguish between a string and a string array. A string is stored in an array of characters and added with "\ 0'

⑤ The length of the character array must be at least one year longer than that of the string

⑥ Use sizeof (array name)/sizeof (Data Type of the array element) to find the length of the character array

7. The character array directly = The comparison result is the comparison address.

7. Use the string operation function provided by string. h:

Strcpy (a, B) copies the string of B to a, and overwrites strcat (a, B): Concatenates the content of string B to the end of string.

Strcmp (a, B): compares each character string a and B from left to right according to the ascII code value until different or '\ 0' is displayed, and ends the comparison.

If the content is the same, return 0; a is greater than B, return a positive integer; a is less than B, return a negative integer

Strlen (a): returns the length of the string, excluding the string ending sign '\ 0'




Download learning resources:


Related Article

Contact Us

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.