An array name is not a pointer.
     1. Quick Review of Arrays
     2. Pointer Notation and Arrays
     3. Using malloc to Create a One-Demensional Array
     4. Using the realloc Function to Resize an Array
     5. Passing a One-Dimensional Array of Pointers
     6. Using a One-Dimensional Array of Pointers
     7. Pointers and Multidimensional Array
     8. Passing Multidimensional Array
     9. Dynamically Allocating a Two-Dimensional Array
     10. Jagged Array and Pointers

Section 1. Quick Review of Arrays

     An array is a contiguous collection of homogeneous elements that can be accessed using an index.
     The realloc function and variable length arrays(C99) provide techniques for dealing with arrays whose size needs to change.

1.1 One-Dimensional Arrays

     A one -dimensional array is a linear structure.
     int vector[5];
    
     The array name simply references a block of memory.
    

1.2 Two-Dimensional Arrays

    
    
    
     
     
1.3 Multidimensional Arrays

     
     

Section2. Pointer Notation and Arrays

     We allocate memory from heap and then treat the memory as if it were an array.
     When an array name is used by itself, the array’s address is returned.
     &vector returns a pointer to the entire array,  an array of integers.
     pv[i] is evaluated as *(pv + i)


     vector and &vector[0] are equivalent, return the address of vector
    

     “Shift and dereference” : The expression vector[2] means start with vector, which is a pointer to the beginning of the array, shift two positions to the right, and then dereference that location to fetch its value.


2.1 Differences Between Arrays and Pointers

     The notation vector[i] generates machine code that starts at location vector, moves i positions form this location, and uses its content;
     Tho notation *(vector+i) generates machine code that starts at location vector, adds i to the address, and then uses the contents at that address.

    int vector[5] = {1,2,3,4,5,};
    int *pv = vector;
     
     differences:
     (1)  sizeof(vector) = 20, sizeof(pv) = 4;
     (2)  pv is an lvalue, could be modified;  
          vector is NOT an lvalue, can NOT be modified.
          
          pv = pv + 1;  // ok
          vector = vector + 1; //syntax error
          pv = vector + 1; // ok

 Section3, Using malloc to Create a One-Demensional Array

    
    

 Section4. Using the realloc Function to Resize an Array

    
PS: currentPosition = newBuffer + (currentPosition - buffer);
explanation:
     befor: buffer = 500, currentPostion = 510, 这个时候来了第10个字符, 是个空格字符 space, ascii 32
     after: 因为new buffer  copy了buffer的内容,所以要将currentPosition指向new buffer;
               newbuffer = 1000, currentPosition = 1010
     
     main:
    
    
     

PS
(1) strlen(“cat”) = 3, malloc内存空间要4,最后一位放NUL或0或’\0’;  “cat”存在长度为10的内存空间中strlen还是3。
(2) strcpy(buffer, “cat”), 具体不确定,但buffer长度应该需要4,猜测是从头开始copy的,最后加0;
(3) while (*old) {
          *(new++) = *(old++);
     }
     这个。。。括号还有用吗。。。
     等价为:
     while (*old) {
          *new = *old;
          new++;
          old++;
     }

Section 5. Passing a One-Dimensional Array of Pointers

5.1 Using Array Notation

    

PS:  the definition of a function that with an array parameter.
     void displayArray(int arr[ ], int size);

5.2 Using Pointer Notation

     

     无论arr[] 还是* arr都可以用arr[i], *(arr+i);

Section6. Using a One-Dimensional Array of Pointers

    
    
这个知识点掌握的不好。page 92
int* arr[5];  这是什么? 这是指针数组,即一个数组arr, 每个数组里的值是指针(是地址)。
所以:
     arr:  an array of pointers;当然也表示 arr[0]的地址100;
     arr[0] : 是个指向int的指针(地址)500。
     *arr[0] : 指针的dereference, 0;
另一种表示:
     *(arr+0) : arr[0]
     **(arr+0) : *arr[0]

int (*arr)[5] : 这个就不一样了,参见section8,这是二维数组。

Section7. Pointers and Multidimensional Array

    
    

    
     
    

Section 8. Passing Multidimensional Array
    
    
    

     int arr[][5] = (int* arr)[5] <> int* arr[5]

     当不确定列数的做法:
     
    
    

     书中解释为什么a[i][j]不能用:
     This is not possible because the pointer is not declared as a two-dimensional array. 
     However, it is possible to use array notation. (arr + i)[j].
     We can use a single subscript since it will be interpreted simply as an offset within the array, whereas two subscripts cannot be used because the compiler doesn’t known the size of the dimensions.


     3 Dimension:
     
     
     

Section9. Dynamically Allocating a Two-Dimensional Array

     int matrix[2][5] = {[1,2,3,4,5},{6,7,8,9,10}},  Memory is allocated contiguously.
     用malloc出来的不一定连续。 因为是an array of arrays.

9.1 Allocating  Potentially Noncontiguous Memory

    
     *(&matrix[0] + i)  or
     *(matrix + i)
    
     

9.2 Allocating Contiguous Memory

    
Section 10. Jagged Array and Pointers

     A jagged array is a two-dimensional array possessing a different number of columns for each row.
     
     
     Compound literal: A compound literal is a C construct that consists of what appears to be a cast operator followed by an initialiser list enclosed in braces.
     e.g.
     (1) (const int) {100}
     (2) (int[3]) {10,20,30}


问题来了:
     int * arr[ ];               :  arr is array of pointer to int
     int (*arr) [ ];             :  arr is pointer to array of int
     int (*(arr[ ]));            :  arr is array of pointer to int 
                                             () : function returning
     
   char *(*(**arr[][8])())[]; // huh ?????

     The "array of" [] and "function returning" () type operators have higher precedence than "pointer to" *
     In arrays, only the leftmost [] can be undimensioned.