C Language review--arrays

Source: Internet
Author: User

Generation of arrays: data is a container for storing data. So: The elements inside an array are of the same type.


One-dimensional arrays:

1. Definition: type name [number of elements]

Note: The number of elements must be integers, there is no concept of objects in C, so the basic data types are stored, and the arrays in OC must be objects.

Before C99, the number of elements must be defined at the time of the sub-compilation, and after C99, there can be no undefined.

The eg:int[10];//represents an array of 10 elements, which is an integer type.

2. Features:

1) All elements are of the same type.

2) Once created, it cannot be changed.

3) The elements in the array are sequentially sorted in memory.


Icon:

Gets the value that is specified by the index

The index starts with subscript 0. To Length-1


3, the initialization of the array,

1) If you define it as above, we can initialize it at any time, either by indexing it by index, or by traversing the assignment.

2) Set initialization, Eg:int a[] = {1,3,4,5,6,7,8,9,}; Or:int a[10] = {1,2,3,44,5}; No, it will be 0, and the extra will be cut off.


4. sizeof () function, which occupies the size of memory in the entire array, in bytes.

Eg:sizeof (a)/sizeof (a[0])//divide to get the number of cells in the array.

sizeof (a[0])//Find out the size of a single element in the array, in bytes


5. Access to the elements in the array is done by iterating through the index to get all the elements that we can

Can not: int a[] ={1,2,3};   int b[] = A; This is a wrong way of writing.

The variables in the array are not assignable in this province, and to be assigned to another array must be traversed.


6, the array as a parameter:

When you pass in an array, you need to pass in an argument that represents the size of the array.

1) cannot be in [] the size of the array everywhere

2) can not use sizeof () to calculate the size of the array, when defining the EG function

Eg:int Search (int key, int a[], int length)//This function is to look up an array of key keys in the array length.


Two:

Two-dimensional arrays: corresponding to the same as a one-dimensional array, can correspond.

Its structure:



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

C Language review--arrays

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.