An array of basic C-language basics-the perfect combination of math and programming

Source: Internet
Author: User

An array of basic C language basics-the perfect combination of math and programming (figure)
Sister again to update, just after the weekend, is not playing very happy Ah, relax after we come to learn new knowledge it!
Now we want to talk about arrays, programming is often closely related to mathematics, presumably in our high school have learned to set it. So how do we represent the assembly in programming? The little cutie who just learned how to program can learn the variables and find that if I need to store the value of the consent function with a lot of variables, I need a lot of variables.
Now let the little sister introduce you to the next two-dimensional array, small cute can be seriously learned Oh! Remember to praise your little sister? ( ′??? ') than the heart
We all play vibrato, we each have a vibrato, we will also pay attention to some of the small sister's vibrato, then the program is how to save this information, below we look at this Picture It!

Let's hurry and learn how to use arrays.
Declaring a two-dimensional array
To declare an array in C, you need to specify the type of element and the number of elements, as shown in the two-dimensional array of int:
int arrayname [10][10];
Initialize a two-dimensional array
After creating the array, the contents are the default values, and we need to assign them to what we want.
Content, you can use the following method
Double Balance[5][1] = {{1000.0}, {2.0}, {3.4}, {7.0}, {50.0}};
The meaning of this code is to declare an array of length 5, and the value of each element is assigned value, the specific content is 1000.0, 2.0, 3.4, 7.0, 50.0, so we {} can not be more than 5 numbers, if you omit the size of the array, The size of the array is the number of elements at the time of initialization. You can initialize the array with this method
Double balance[][] = {{1,2,3,4,4},{1,23,4},{1,2,3},{1,2,5}};
This time, his length is still 4, in {} add another {} to become 5.
Accessing two-dimensional array elements
We've learned to store content inside, but how do we get it out? Array elements can be accessed through the array name and index. Mrs. Bovary , the index of the element is placed in square brackets, followed by the name of the array. For example: double salary = balance[9][1];
This is the 10th element of the 2nd element is taken out to assign value to salary, some small wide resistance to ask, obviously not 9, how to say as 10th, hit a typo. In fact, most of the programming language used to count, is starting from 0, the first is the element is 0 OH
In this, can we also assign a value to a single array element, such as the fans of a certain classmate rose a
We're going to update the elements inside, so we can
Double salary = balance[9][1];
BALANCE[9][1] = salary + 1;

An array of basic C language basics-the perfect combination of math and programming (figure)

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.