(C) A simple understanding of arrays and pointers.
Because I didn't understand it in the classroom, and I couldn't understand the obscure expression on textbooks ("C Language Programming Tutorial", edited by Tan haoqiang, Zhang Kewen, I used the book "C language entry classic" to study the array and pointer for one night.
Let's start with a simple program:
1 #include<stdio.h> 2 3 int main() 4 { 5 char board[3][3]={ 6 {'1','2','3'}, 7 {'4','5','6'}, 8 {'7','8','9'} 9 };10 11 12 printf("value of board[0][0] : %c\n", board[0][0]);13 14 printf("value of *board[0] : %c\n", *board[0]);15 printf("value of **board : %c\n", **board);16 17 18 19 return 0;20 21 }
1 Output: 2 3 value of board [0] [0]: 1 4 5 value of * board [0]: 1 6 7 value of ** board: 1 8 9 10 11 board [0] [0]
In the two-dimensional array board [3] [3:
The board is equivalent to a pointer (* board/board [0]) pointing to the first element of the 0th sub-array, that is, the first element of the Two-dimensional array board [3] [3. That is, the board represents the address of the 0th sub-array in the two-dimensional array.
* Use the cancel quote operator * to cancel the reference to the pointer of the board and obtain the value indicated by the board. * The board is equivalent to a pointer pointing to elements in the 0th sub-array. * Board is equivalent to board [0] (* board = board [0]), that is, the address of 0th elements in the 0th sub-arrays in a two-dimensional array.
** Board again uses the cancel operator * to cancel the reference to the * board pointer and obtain the value indicated by * board. That is, ** board is the value of 0th elements in the 0th sub-array.
Board [0] is equivalent to a pointer pointing to 0th elements in the 0th sub-array, that is, the first element of the first sub-array of the Two-dimensional array board [3] [3. That is, board [0] is the address of the 0th elements in the 0th sub-array.
* Board [0] use the cancel operator * to cancel the reference to the pointer of board [0] and obtain the value referred to by board [0. That is, * board [0] is the value of the 0th elements in the 0th sub-array.
Board [0] [0] is equivalent to a variable name.
* Board [0] And ** board are applications equivalent to pointers to arrays.
This is what I learned last night.
This is the first time I posted a post on the blog. I am not sure whether my summary is correct or I have a more concise and thorough understanding. I would like to ask all like-minded students and Daniel to criticize and advise me. Thank you ~