C Language Basics Tutorial (iv) Pointers, structures, unions, and enumerations (6)

Source: Internet
Author: User
Tags integer printf
2.2.2 points to an array pointer consisting of n elements
In Turbo C, you can define the following pointer variables:
int (*p) [3];
The pointer P refers to an integer array pointer consisting of 3 elements. In the definition, parentheses are not small, otherwise it is an array of pointers, which is described later. The pointer to this array differs from the integer pointer described earlier, and when an integer pointer points to an integral array of elements, with the pointer (address) plus 1, which indicates the next element to the array, the address value increases by 2 (because the magnification factor is 2), and as defined above, points to a 3-element array pointer. The address value is increased when the address is added to the 1 operation
6 (the magnification factor is 2x3=6), this array pointer is used less in turbo C, but it is convenient when dealing with two-dimensional arrays. For example:
int a[3][4], (*P) [4];
P=a;
At the start, p points to the No. 0 row of the two-dimensional array, and when the p+1 operation is performed, the magnification factor is 4x2=8 at this point, so it exactly points to the 1th row of the two-dimensional array. As with the rules for computing two-dimensional array element addresses, *p+1 points to a[0][1],* (P+i) +j points to the array element A[i][j].
Example 1
int a[3] [4]={
{1,3,5,7},
{9,11,13,15},
{17,19,21,23}
};
Main ()
{
int I, (*b) [4];
b=a+1; /* b points to line 1th of a two-dimensional array, at which point *b[0] or
**b is a[1][0] * *
for (i=1;i<=4;b=b[0]+2,i++)/* To modify the point of B, 2 per increment * *
printf ("%d\t", *b[0]);
printf ("\ n");
For (i=0 i<2; i++) {
B=a+i; /* Modify the point of B to skip the two-dimensional array each time
One line * *
printf ("%d\t", * (b[i]+1));
}
printf ("\ n");
}
The results of the program operation are as follows:
9 13 17 21
3 11 19

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.