4. Array of OBJECTIVE-C programming

Source: Internet
Author: User

1. Defining Arrays

Syntax format:
Type Arrname[length]

Length can be either a fixed integer value or an integer variable or an integer expression.

If the element is not initialized when the array is defined, the default value is assigned to the element. The integer type is 0, the float is 0.0, and the pointer type is nil.

The array itself holds the address of the first element (the first address).

Calculate the address of each element:
Element address = First address + memory size of array variable * index


2. Initialization of arrays

Syntax format:
Type Arrayname[length] = {value1, value2, Value3, value4 ...};

When you specify an element of an array, that is, an array that specifies initialization values, can be specified for all elements, or specified for the preceding section elements. You can only assign an initialization value if you do not specify it.

If the initial value of all array elements is specified at initialization time, the specified length can be omitted, because the number of elements in the group is automatically calculated to determine the length.


3. Using Arrays

Do you remember square brackets? The-->[] will be used here.

After the array initialization is complete, you cannot assign values to the group itself.

The array index is starting from 0. Arr[0], takes the first array element.

The OC itself does not provide methods or related properties to access the length of the array, but the sizeof () function can be used to calculate the length of the array.
Use the following:
sizeof (ARR)/sizeof (Arr[0])
However, sizeof (ARR) returns the number of bytes consumed by the entire array, and sizeof (Arr[0]) plays the first number of bytes that are consumed by the element, and the length of the arrays can be counted.


4. Multidimensional Arrays

Two-dimensional arrays
Syntax format:
Type Arrayname[length][length]

Understand:
It looks like a two-dimensional array or a one-dimensional array, which means that the elements of one-dimensional arrays are also one-dimensional arrays.

Example:
ARR[2][3]
The above shows that the array arr has two elements,
Arr[0], it has three elements, arr[0][0], arr[0][1], arr[0][2]
ARR[1], it has three elements, arr[1][0], arr[1][1], arr[1][2]

Initialization of multidimensional arrays:

A multidimensional array is ultimately a one-dimensional array, like an n-dimensional array that is equivalent to an array element as a one-dimensional array of n-1-dimensional arrays.


Fourth Chapter, End!

This article is original, reproduced please specify the source, prohibited for commercial use. Thank you!

http://blog.csdn.net/zsfz_053/article/details/42527169


4. Array of OBJECTIVE-C programming

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.