Chapter 2 pointer (iii) classification of addresses-pointer type

Source: Internet
Author: User

 

We already know that the pointer is the first address.
In our daily life, we met a person, and then we contacted him by phone. Of course, the relationship is better. We can leave his address to visit him. So we use a book to record the phone number and address. This book records the phone address, which we often call. Now we have a phone book in our mobile phone, powerful phone book and address recording function. We can find them through the address. Therefore, record addresses are a daily task.
In the computer, we define a variable A, and then we use variable name a to access it. Of course, deep programming also leaves the first address of a for access. So we need to record the first address of a. in C language, we can use variable B to record the first address of A. Here, B is a special variable, it is a variable used to store addresses. We will describe the definition of such address variables later. Through the address in B, we can find. Therefore, it is necessary for us to store the first address in C programming.

Well, now, we first classify the possible addresses in the address book,
In daily life, our address book is a book, where the addresses are classified by friends, classmates, colleagues, relatives, friends, and so on, and can be distinguished by pens of different colors! For example, a red pen address represents a friend. Black pen, representing students. Yellow pen, representing colleagues. A green pen represents a relative. A blue pen represents a friend.

in computer programming, our address book stores the first addresses of some variables or functions. We cannot use colors to classify addresses. Instead, we classify addresses by integer, floating point, character, array, function, and so on, it can be divided into integer addresses, floating point addresses, character addresses, array addresses, function addresses, and so on. That is to say, addresses are of different types. These types are complex and need to be distinguished and memorized carefully!
1. Common variable type of the first address:
we are familiar with it. variables defined by INT can be stored in-32768 ~ + An integer in the range of 32767. The first address of this variable is of the type int *. Here * indicates the address type.
for example, if int A exists, the first address of int A is abbreviated as & A, so the type of & A is int *

If there is a Type correspondence between the int variable and the first address of the int variable,
Then, the variable is of the int type. Correspondingly, the first address of the variable is of the int * type, abbreviated:
Int ---- >>>> int *
Similarly, float ---- >>> float *
Char ---- >>>> char *
Unsigned ---- >>>> unsigned *
Long ---- >>>> long *
.....................

2. One-dimensional arrayType of the first address:
Int ---- >>>> int * float ---- >>>> float * char ---- >>>> char *;
For example: int A [10]; its first address is array name a, so a is of the int * type.
In this array, the type of the first address of any element, It is also int * type .
For example, the first address of a [5] Is & A [5], It is also int * type

3. Two-dimensional arrayType of the first address:
Assume that a 2-dimensional array is defined as follows:
Int A [3] [4];
Then, enclose int A [3] [4] in parentheses into int (a) [3] [4], and then convert the array name *, that is, INT (*) [3] [4]. Then, remove [3], which indicates the number of rows, and convert it to int (*) [4]. is the type of the 2-dimensional array address.

Int A [3] [4]; ------ >>> int (*) [4]
Generally, the two-dimensional int array name [array rows] [N] ----- >>>> int (*) [N], and each row of the Two-dimensional array must have n columns.

The same is true:
Two-dimensional float array name [array rows] [N] ----- >>>> float (*) [N]
Two-dimensional char array name [number of array rows] [N] ---- >>> char (*) [N]

4. FunctionsType of the first address:
For a function, suppose there is a function int F (void ){...}, then, INT (*) (void) is used as the type of its first address (also known as the entry address.
How does this type come from? It is to enclose the int F (void) in parentheses of the function header into int (f) (void), and then convert the function name to *, that is, INT (*) (void) is the type of the function entry address.
Int F (void) {...} ---- >>> int (*) (void)

From the above we can see that the address type uses *
We already know that the first address is the pointer, so the above address type is the pointer type.
The first level of learning pointer is to be familiar with the complicated Writing of address types. This is the first level that must be crossed.

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.