Dark Horse programmer--c Pointers in language (6)

Source: Internet
Author: User

------Java Training, Android training, iOS training,. NET training, look forward to communicating with you! -------

Summary of this chapter

1. pointers are an important part of C language, and using pointer programming has the following advantages:

(1) improve the compiler efficiency and execution speed of the program.

(2) A pointer can be used to share variables or data structures between the keynote function and the tuned function, enabling bidirectional data communication.

(3) Dynamic storage allocation can be implemented.

(4) easily represent a variety of data structures and write high-quality programs.

2. operation of Pointers

(1) Fetch address operator & : Find the address of the variable

(2) Fetch content operator * : Represents the variable that the pointer refers to

(3) Assignment Operation · assigning variable addresses to pointer variables · reciprocal assignment of pointer variables of the same type · assigns an array, the first address of the string, to the pointer variable · Assigning a function entry address to a pointer variable

(4) addition and subtraction operations on pointer variables that point to arrays, strings can be added and reduced, such as p+n,p-n,p++,p-- . The two pointer variables that point to the same array can be subtracted from each other. It makes no sense to add and subtract pointers to other types of pointer variables.

(5) A relational operation that points to two pointer variables of the same array can be greater than, less than, equal to the comparison operation. The pointer can be compared with 0 , andp==0 indicates that p is a null pointer.

3. the various notes and meanings related to pointers are shown in the table below.

int *p; P is a pointer variable that points to an integral type

int *p[n];    P is an array of pointers, consisting of n pointer elements that point to an integral type.

int (*p) [n];   P is a pointer variable that points to an integer two-dimensional array, and the number of columns in the two-dimensional array is n

int *p ()     P is a function that returns a pointer value that points to an integral type

Int (*p) ()    P is a pointer to a function that returns the integer amount

int **p P is a pointer variable pointing to another pointer, which points to an integral type.

4. Many instructions for pointers are made by combining pointers, arrays, and function descriptions. but it is not possible to combine them, for example, an array cannot be composed of functions, that is, an array element cannot be a function, and a function cannot return an array or return another function. e.g. int a[5] (); it's wrong.

5. With regard to parentheses when interpreting the combo specifier, the brackets and parentheses to the right of the identifier take precedence over the "*" number on the left side of the identifier, while the brackets and parentheses are combined from left to right with the same precedence. However, you can use parentheses to change the binding order of the conventions.

6. The rules for reading the combo specifier are " from Inside Out ". starting with the identifier, look at the right side of the incompetence Allende bracket or the square bracket, if there is a first explanation, then see the left has no * number. If you encounter closing parentheses at any time, you must use the same rules to process the contents of the parentheses before continuing. For example: int* (* (*a) ()) [10]↑↑↑↑↑↑↑7 6 4 2 1 3 5 above gives an inward reading order,

The following explains it:

(1) identifiers a be described as;

(2) A pointer variable, which points to;

(3) a function, which returns;

(4) a pointer to which the pointer is pointing;

(5) One has Ten An array of elements whose type is;

(6) pointer-type, it points;

(7) int type data.

So a is a function pointer variable, and the function returns a pointer value that points to an array of pointers, and the elements of the pointer array point to the integer amount.

Dark Horse programmer--c Pointers in language (6)

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.