(C) A simple understanding of arrays and pointers.

Source: Internet
Author: User

(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 ~

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.