Array Definition In C Language: One demension definition cast, DataType ArrayName[Size]; Two demension definition cast, DataType ArrayName[SizeX][SizeY]; Instantation only definition without initialization int a[10];//define a one-demesion array which is composed of ten integer sequence. char b[3][4];//define a two-demesion charactor array(column size is 3 and row size is 4). //initialization here Instantation initialization while definition int a[10] = {1, 2, 3, 4};//innitial the first four integer elements, compiler specify the others numerical zero char b[3][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};//innitial the whole arrary Caution: when refer the element, the subscript grows begins 0, 1, 2, ... , size-1. a[0] is the first element's content.
Pointer Definition In C Language Signification DataType* PointerVariable; Point to a address of DataType variable DataType* PointerVariable[Size]; A pointer array in which all element point to address of DataType (DataType* PointerVariable)[Size]; Point to consecutive size length memory of DataType DataType** PointerVariable; Point to Pointer Variable Instantation (note a and b symbol refers in array definition above) int* p1 = a;//p point to the first element of array, symbal 'a' represent the first element address of array (int* p2)[10] = &a; //p point to a consecutive ten integer variable memory address,'&a' is the header pointer of this array and its value is equal to 'a',but meaning is differece from 'a'.
(int* p3)[4] = b;// p point to the first row header of 'b' matrix, b herein represent &b[0]. int* p4[3] = {&b[0][0], &b[1][0], &b[2][0]};//define a pointer type array, the memory contains the header of 3 rows respectively. int **p5 = &p1; // pointer p5 point to pointer variable p1
|
文章评论(0条评论)
登录后参与讨论