Summary of the experiment Six

Source: Internet
Author: User

Array

definition: An array is the most basic constructed type, the elements in the array are stored in memory continuously, each element belongs to the same data type, and the array element can be uniquely determined with the array name and the following table.

definition of an array: Defining an array requires an explicit array variable name, the type of the array element, and the size (number of elements).

The general form is: type an array group name "Array Length"

Type name is the type of each element

Array name is the name of the array variable

The array length is an integer constant expression that sets the size of the array.

references to arrays: The C language specifies that only a single array element can be referenced, but not the entire array at a time.

References to array elements to make subscript: array Name "subscript"

subscript: Can be an orthopedic expression , his value range is          "0, array Length-1"

Examples of how array elements are used:

 1  int  k,a[ 10  ];  2  k=3  ;  3  a[o]=23  ;  4  a[k-2 ]=a[ 0 ] +1  ;  5  scanf ( " % D  ), &a[9 ]) 

Array definitions and references need to use the array name "shaping expression", but when defining an array: The square brackets are constant expressions , which represent the length of the array , which can be constants, symbolic constants, but not variables , the length of the array the definition must be made and cannot be changed.

When referencing an array: In square brackets is an expression , the subscript, can be a variable , reasonable value range is "0, array Length-1".

Initialization of the array:

When you define an array, you can also assign an initial value to a group element.
General form: Type an array group name [array length]={initial table}

int a[]={1,2,3,4,5,6,7,8 ,9,ten};

If the statically stored array is not initialized, the system automatically assigns 0 to all elements.

Static int b [5]; Static int b [5]={0,0,0,0,0};

The initialization of an array can also be specific to only a subset of elements

Static int b [5]={1,2,3};

When an array is initialized, the array length can be omitted if all elements are assigned an initial value

int A []={1,2,3,4,5,6,7,8,9 ,ten}; int A []={1,2,3,4,5,6, 7,8,9,ten};

Here is the code:

#include <stdio.h>intMain () {inta[ +]={1,1}; inti;  for(i=2; i<= +; i++) {A[i]=a[i-1]+a[i-2]; }     for(i=0;i< +; i++) {printf ("%10d", A[i]); }    return 0;}

Summary of the experiment Six

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.