C + + arrays

Source: Internet
Author: User

1. Definition of arrays

An array is represented by a set of values, for example:

Char arr[10];

Arr is an array name, and a char is an array type. Indicates that there are 5 char types of data.

The meaning of an array is equivalent to arranging n variables of the same type.

2. Length of the array

The length of the array is specified in brackets and must be an integer constant.

such as: int arr[12];

You cannot use a variable to represent the length of an array. For example:

int size=12;

int att[size];

This writing is wrong.

3. Initial value of the array

You can specify an initial value for an element when you define an array.

Example: Char arr[5]={90,91,92,93,94};

Syntax requirements: Use a semicolon after curly braces, curly braces. Elements are separated by commas.

You can specify an initial value, or you can specify a partial initial value

4. Length of the array

Use sizeof to get the size of the array length

int arr [100];

int size=sizeof (arr);

5. Two-dimensional array

Type name [N][m];

6. Initialization of two-D arrays

int a[4][3]

{

{11,12,13},

{11,12,13},

{11,12,13},

{11,12,13},

}

C + + 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.