Array notes, array

Source: Internet
Author: User
Tags array definition

Array notes, array
1. array definition: array name of the array type [length], where the length must be an integer greater than 0/* In this sentence, the length of the array must be specified. Do not write it: int a [I]; I = 10; it should be written as: Int a [10]; macro definition and malloc function can also be used to define macro definition Syntax: # define N 10Int a [N]; */2. the types of each element in the array are the same; 3. an array is an ordered array stored in the memory in order, and the memory address is from small to large; // The memory address is from small to large because there is only a accumulator In the CPU, the existence of no accumulators 4. the array name is the address of the first element of the array, that is, the first address of the array. Of course, it can be understood that the array name is an address constant; 5. an array (such as int a [n]) is known. How to calculate the number of elements in an array (that is, to obtain the value of n) If you only know the array name and the number of elements in the array) answer: sizeof (a)/sizeof (a [0]);/* The first sizeof (a) is to calculate the length of the entire array, followed by sizeof (a [0]) Calculate the length of the first element in the array. Because each element in the array has the same type, the memory length of each element is the same, and the array must exist in a [0] */6. data Element initialization:. the number of elements initialized in the array cannot exceed the set length. B. if the number of elements initialized in the array is not enough, the length will be later !! Auto-fill 0; C.int a [] = {1, 2, 3, 4, 5}; this statement is valid even if no length is specified, however, the elements initialized later are automatically filled in the memory, and the length of the array is obtained during compilation. That is, the compiler divides the memory area according to the number of elements initialized by the array. 7. during compilation, the C language does not check whether the subscript of the array is out of bounds. However, during the running process, the kernel reports the "segmentation fault (core dumped)" segment error. // If an invalid memory area is operated during the running of the program, the operating system forcibly terminates the program to protect the data integrity in the memory, the "segment error" is reported because the subscript of the array is out of bounds, or the pointer does not point to a valid element...

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.