multidimensional arrays and pointers {notes}

Source: Internet
Author: User

A: Represents a two-dimensional array name, pointing to a one-dimensional array a[0], that is, 0 header address;

a[0],* (a+0), *a: represents 0 Rows 0 column element address;

a+1,& (a+1): 1 header Address

a[1]+2,* (a+1) +2,&a[1][2]:1 row 2 column element a[1][2] Address

* (a[1]+2,* (* (a+1) +2), a[1][2]:1 row 2 column element a[1][2] Value

A two-dimensional array name is a pointer to a row;

For example, a and a+1 are pointers to rows, in front of which are *a and * (a+1), they are pointers to columns, respectively, to the elements of array 0 row 0 columns, and 1 rows and 0 columns, and vice versa, by adding & to the pointer to the column, which is a pointer to the row;

&a[i] or a+i points to the row, A[i] or * (a+i) to the column, when the column is labeled 0 o'clock, &a[i] and A[i] (that is, a[i]+j) values are equal, that is, the same address value, but the object is different, the pointer type is different;

In a two-dimensional array, the values of A+i, A[i], * (A+i), &a[i], and &a[i][0] are equal and are the same address values;

Example:

#include <studio.h>
#define FORMAT "%d,%d\n"
void int main ()
{
int a[3][4]={1,3,5,7,9,11,13,15,17,19,21,23};
printf (format,a,*a);
printf (format,&a[0],&a[0][0]);
printf (format,a[1],a+1);
printf (format,&a[1][0],* (a+1) +0);
printf (format,a[2],* (a+2));
printf (format,&a[2],a+2);
printf (format,a[1][0],* (* (a+1) +0));
return 0;
}

multidimensional arrays and pointers {notes}

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.