Program Ape--c Language Details 13 (two-dimensional array and pointers, &*a[i][0] understanding, array 1[e] and e[1] you probably haven't seen it.

Source: Internet
Author: User

Main content: two-dimensional arrays and pointers, &*a[i][0] understanding, arrays 1[e] and e[1]

#include <stdio.h> #define NUM_ROWS 10#define num_cols 10int Main (int argc, char **argv) {    int a[nu M_rows][num_cols], *p, i = 0; A is interpreted as a pointer to an integer pointer that is int * *     int C, d=2,*test, e[2] = {4,5},f[2][2] = {{11,22},{33,44}}; e understood as int *     test = &d;//    c = *&test; As with & (*test) results, * and & same priority, right-to-left     c = &*test; Attention and ++*test difference, here is a bit not understand, why & (*test) not error, I                 //sense is *test equivalent to D, not a specific value, and then & (*test) equals & (d)                 //So it is confirmed that the following pointer operation & and * can be canceled//    c = ++*test;     printf ("1[e] =%d\n", 1[e]); 1[e] and e[1], as for the compiler e[1] equivalent to * (E + 1) ==>* (1 + E)            & Nbsp;                   //is equivalent to 1[e], but good programming habits do not write this     printf ("c =%d\n", c);    printf (" D is the address =%d\n ", &d);//    test = &*e[0];  //This error (*&e[0] compile through but run error), the pointer can be & and * Cancel, e[0] is constant,                     //below f[1] indicates the second row//    printf ("constant d =%d\n", *test);    test = & *f[1];    printf ("D =%d\n", *test);    for (i = 0; i < num_rows; i++)     {          /* causes p to point to a row in a two-dimensional array with P = &a[i][0] equivalent to P = a[i]          * Two-dimensional arrays in C language storage by row          * The magic formula between array subscript and pointer arithmetic operations          * for any array a , A[i] equivalent to * (a+1) .         * because & and * can be canceled, then &a[i][0] equivalent to & (* (a[i]+0)) ==> equivalent to &*a[i] ==>a[i]         */&Nbsp;       for (p = a[i]; p < a[i] + num_cols; p++)         {&nbsp ;           *p = i;             printf ("%3d", *p);        }        printf ("\ n");             }     return 0;}

Output:


Program Ape--c Language Details 13 (two-dimensional array and pointers, &*a[i][0] understanding, array 1[e] and e[1] you probably haven't seen it.

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.