Garbage collection array in C Language

Source: Internet
Author: User

Garbage collection array in C Language

--- Restore content start ---

Learning c language knows that arrays and pointers have a special position in c. It is also a must-have knowledge that will benefit you from learning it.

I. Array

1. array: composed of a series of identical elements. It is continuously stored in the memory.

2. array declaration:

Format: type array name [number of elements];

Example: int myarray [10];

Note: Before c99, the number of elements is variable.

Example:

Int n = 10;

Int myarray [n]; // not allowed before C99 (Initialization is not allowed for this declaration method)

3. array initialization:

  • Int myarray [] = {1, 2, 3, 4, 5}; // correct. In this case, the number of elements can be omitted.
  • Int myarray [10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; // In general, "," is used between the element and the element.
  • Int myarray [10] = {1, 2, 3}; // only initialize the first three elements.
  • Int myarray [10] = {[4] = 4, [6] = 6}; // The first 5th elements are initialized, and the other elements are all 0.
  • Int n = 10; int myarray [n] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; // error. After C99, variables can be used as the number of elements in the array, but such declarations cannot be initialized.

If we do not initialize the array after it is defined, what is the value of the array element?

When an array is defined, it just draws an area and uses the array name to store array elements. However, when defining an array, the data in this area is not changed. That is to say, the value in this area is uncertain.

4. array assignment

  • Int myarray [10] = {1, 2, 4, 5, 6, 7, 8, 9, 0 };
  • Int oarray [10];
  • Oarray = myarray; // error. c does not support assigning values to an array as a whole.
  • Oarray [10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; // error. c does not support a value enclosed by curly brackets.

5. array Boundary

When using arrays, note that the array index cannot exceed the array boundary. That is to say, the array index should be valid for the array.

   

--- Restore content end ---

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.