C Language Pointers

Source: Internet
Author: User

Prepare content: The address of the variable, the contents of the variable, direct addressing, and indirection.

(1). The address of the variable

The first address of the storage space that the variable occupies in memory.

(2). The contents of the variable

(3). Direct addressing

Access to the contents of a variable directly by variable name.

(4). Indirect addressing

Indirectly access the variable (such as a) to which it points through a pointer variable, such as P.

1. What is a pointer?

In order to access these memory cells correctly, each memory unit must be numbered. The number of the memory unit is also called the address. Since the memory unit can be found according to the number or address of the memory unit, it is often referred to as a pointer.

2. What is a pointer variable?

In the C language, a variable is allowed to hold a pointer, which is called a pointer variable. In the C language, a data type or structure often occupies a contiguous set of memory units. The concept of "address" does not describe a data type or structure well, while a "pointer" is actually an address, but it is the first address of a data structure, which is "pointing" to a data structure, thus making the concept clearer.

The pointer to the variable is the address of the variable. The variable that holds the variable address is a pointer variable.

3. Definition of pointer variables

The general form is:
Type descriptor * variable name;
where * indicates that this is a pointer variable, the variable name is the defined pointer variable name, and the type specifier represents the data type of the variable to which this pointer variable is pointing.

4. Reference to pointer variables:

Pointer variables, like ordinary variables, need to be defined not only by the description, but also by a specific value. An unassigned pointer variable cannot be used, otherwise it will cause system confusion and even panic. The assignment of a pointer variable can only be assigned to an address and must never be given any other data, or it will cause an error. In the C language, the address of a variable is assigned by the compilation system, completely transparent to the user, and the user does not know the specific address of the variable.

Two related operators:

    • &: Take address operator;
    • *: pointer operator (or "indirect access" operator).


The address operator & is provided in the C language to represent the address of the variable. The general form is:
& variable name;
If &a represents the address of variable A, &b represents the address of variable B.

5. Application of pointer variables

C Language Pointers

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.