C language 03

Source: Internet
Author: User

To understand the array, first recognize the "address" in memory

I. Address

1. The memory in the computer is the storage space in bytes. Each byte of memory has a unique number, which is called an address. Every program and data stored in memory has an address, that is, a function has its own memory address.

2. When a variable is defined, the system allocates a storage unit with a unique address to store the variable.

3. During the commissioning process, we take a print view of the variable's address:

Ten;  output address printf in 16 binary form ("16 binary:%x\n", &C);  output address printf in 10 binary form ("10 binary:%d", &c);           

Two. one-dimensional arrays

* The form of the definition is: type array name [number of elements]

int a[5];

[] inside is a fixed value, constant or constant expression, cannot be a variable, in most cases do not omit the number of elements (when the array is initialized as a function parameter and arrays)

When you define an array, the system allocates a contiguous amount of storage space by array type and number to store the array elements, such as int a[3], which occupies a contiguous 6 bytes of storage (in a 16-bit compiler environment, an int type occupies 2 bytes). Note that the array name represents the address of the entire array, which is the starting address of the array.

* Element Value list can be the initial value of all elements of an array, or it can be the initial value of an element in the preceding section

int a[4] = {5}; 

When an array is an integer, initialize an element with an indeterminate initial value, which defaults to 0, so the above a[2], a[3] are 0

* When assigning initial values to all array elements, you can omit the number of elements

int a[] = {7};

Indicates that the number of elements in array A is 3

* Array initialization can only be used for the definition of the array, after the definition can only one element of an element to assign a value

Two-dimensional array initialization, you can omit the number of rows, but you can not omit the number of columns.

Three. String

C language 03

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.