One-dimensional array is used as two-dimensional, and dimension array is used as two-dimensional

Source: Internet
Author: User
Tags array definition

One-dimensional array is used as two-dimensional, and dimension array is used as two-dimensional
# Include <stdio. h>


Int main (void)
{
Int I, j;
Int a [] = {, 35 };
Typedef int (* Type) [5];
Type B = (Type);

For (I = 0; I <5; ++ I)
{
For (j = 0; j <5; ++ j)
Printf ("% d", B [I] [j]);
Printf ("\ n ");
}

Return 0;

}



What is access to a two-dimensional array using a one-dimensional array? What should I do if y (4) and y (2, 1) are the same variables?

This is what LZ can look.
Data storage is stored one by one in order. When a two-dimensional array is stored, the first uniqueness is stored first, and then the second uniqueness is stored: the last and first of the second dimensions of the first dimension are adjacent!
That is to say, when you exceed the number of dimensions in the first dimension, the second dimension is automatically searched!
Therefore, if y (4) exceeds y (3), the first number of y (2, 1) in the second dimension is searched.
LZ can draw pictures to think about it.

How do two-dimensional arrays represent one-dimensional arrays?

Sz [1] [32] = {
{0xff, 0xfe, 0xff, 0xfd, 0xff, 0xfb, 0xff, 0xf7,
0xff, 0xef, 0xff, 0xdf, 0xff, 0xbf, 0xff, 0x7f,
0xfe, 0xff, 0xfd, 0xff, 0xfb, 0xff, 0xf7, 0xff,
0xef, 0xff, 0xdf, 0xff, 0xbf, 0xff, 0x7f, 0xff}
};
This is an array definition. It indicates that the array has one row and 32 columns. The first column of the array starts from sz [0] [0] to sz [0] [31].
Sz [0] [j] refers to the number of j in the first line, for example, sz [0] [3] = 0xff,
Sz [0] indicates the first line of sz [0] = {0xff, 0xfe, 0xff, 0xfd, 0xff, 0xfb, 0xff, 0xf7,
0xff, 0xef, 0xff, 0xdf, 0xff, 0xbf, 0xff, 0x7f,
0xfe, 0xff, 0xfd, 0xff, 0xfb, 0xff, 0xf7, 0xff,
0xef, 0xff, 0xdf, 0xff, 0xbf, 0xff, 0x7f, 0xff}

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.