C language V: two-dimensional arrays, multidimensional arrays

Source: Internet
Author: User

I. Two-D arrays

Definition of a two-dimensional array: Data type array name [constant expression 1][constant expression 2] = {value 1, value 2,.... Value n};

For example:

int Array[3][3] = {{1, 2, 3},

{2, 1, 3},

{3, 1, 2}};

A two-dimensional array array[3][3] is the equivalent of three one-dimensional arrays containing three elements.

Number of array elements how to: two-dimension index multiplication

Accessing elements in a two-dimensional array: double subscript

Multidimensional Arrays:

Three-dimensional array: array name [constant expression 1][constant expression 2][constant expression 3] = {value 1, value 2,.... Value n};

Multidimensional Arrays: Several dimensions, there are several brackets, the access of the element has a few layers subscript, the traversal requires a few layers for the loop

Array of strings:

Char array[constant expression 1][constant expression 2] = {"", "", ...};

Note: The string array, the second dimension, must be 1 larger than the longest string;

To access a single character:

ARRAY[I][J]

Output string:

printf ("%s\n", arra[3]);//access only to the row index,

Output All strings:

for (int i = 0; i < 4; i++) {

printf ("%s", Array[i]);

}

C language V: two-dimensional arrays, multidimensional 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.