Int (* p) [5] Type Analysis in C Language

Source: Internet
Author: User

# Include <stdio. h>
Int main ()
{
Int I;
Int B [5] = {1, 3, 5, 7, 9 };
Int (* a) [5] = & B;
Int * m = a; // the space in the range of a is determined by the int size.
For (I = 0; I <5; I ++)
{
Printf ("% d \ n", m [I]);
}
Return 0;

}

The output result is 1 2 3 4 5.

Here, int (* a) [5] indicates that a space of five int values is generated in the stack. a indicates the first address of the whole space.

Int * m = a; defines its value offset, that is, an integer pointer * m's first address is the first address of the space opened for



To better analyze the following program, you can better understand it:


# Include <stdio. h>
Int main ()
{
Int I;
Short B [5] = {1, 3, 5, 7, 9 };
Int (* a) [5] = & B;
Short * m = a; // the size of the space in the range depends on the int size.
For (I = 0; I <5; I ++)
{
Printf ("% d \ n", m [I]);
}
Return 0;
}

Output result: 1 2 3 4 5

The Space Generated by (* a) [5] is a space of five int types. The first address of the space is the same as the first address of the array, but it is only a space. The value method is not defined, short * m = a; indicates that the short type is used to obtain the space. This type has no relationship with int (* a) [5], int (*) [5] The value is responsible for generating space, with no type. It is a bit similar to the malloc function.

Careful scrutiny is helpful for in-depth understanding.





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.