<24> "Mastering" two-dimensional array pointers definition, initialization +

Source: Internet
Author: User

"Mastering" a two-dimensional array pointer definition, initialization

Array pointer: Defines a pointer variable that points to the element of a one-dimensional array, a two-dimensional array pointer-to-row pointer that points to each row of a two-dimensional array, storing the first address definition format of the row: data type (*row pointer variable name)     [Length of the second dimension of the array]; Initialization of two-dimensional array pointersinta[2][3]; intb[2][2]; floatf1[4][4]; //Suppose I want to define a row pointer to array a//a = &a[0] = &a[0][0] = a[0]   int(*p) [3] =A; Use of two-dimensional array pointers* (* (p+i) +j)//is to get each element of a two-dimensional array 
1#include <stdio.h>2 3 intMainintargcConst Char*argv[]) {4     inta[3][4]={1,3,5,7,9, One, -, the, -, +, +, at};5     6     //two-dimensional array pointers7     //A two-dimensional array pointer can replace the array name to use8     int(*p) [4] =A;9   Ten      for(intI=0; i<3; i++) { One          for(intj=0; j<4; J + +) { A             //iterating through an array -printf"%d\t", * (* (p+i) +j));//If it is * (* (a+i) +j) can, because it is a constant, the equivalent of the address but you above the int *p=a;14}//This time the following * (* (p+i) +j) will be an error, because for this When P is a variable, you * is the value, the definition of a two-dimensional array pointer should be to solve the problem
 15  printf ( " \n   " );  16  }    18 return  0  ;  19 } 
1    3    5    7    9     One     -     the     -     +     +     at    

<24> "Mastering" two-dimensional array pointers definition, initialization +

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.