Data structure review notes-array

Source: Internet
Author: User

Finally, we decided to move towards software developers on the road to the future and review data structures and algorithms from now on.

Arrays have several interesting features.

1. For the array int list [3], the compiler interprets list [I] as a pointer to an integer with the address list + I * sizeof (INT.

For int * List and int * list2 [5], both are int-type variables, but the compiler will allocate the latter five integer buckets.

List2 actually points to list2 [0], and list2 + I is actually & list2 [I]. You do not need to add an offset in the C language. Therefore, * (list2 + I) = list2 [I];

2. in C language, arrays are used as parameters. functions that accept arrays as parameters do not actually allocate space to arrays repeatedly. It can be understood that when arrays are used as parameters, they only pass their addresses in, (Like address transfer), so changes to the parameter array in the function will also be reflected in the array itself.

/* For example */INT sum (INT list [], int N) // n is the dimension.

{

For (INT I = 0, I <n; I ++)

{

List [I] + = I;

}

}

Sum (A, 3 );

In this example, the real parameter A = & A [0] is first copied to a temporary Unit to become the specific value of the form parameter list. In the function body, if list [I] appears on the left of the value assignment statement, it indirectly references the value pointed to by (list + I). If list [I] appears on the right of the value assignment statement, the result on the right of the equal sign is saved to the unit (list + I ). this example tells us that although the C language function is called to pass values, the array as a function parameter does not pass the specific array content.

 

Data structure review notes-array

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.