Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - What's the difference between the address symbol and * in C language?
What's the difference between the address symbol and * in C language?
Not all are addresses.

1, symbols have different meanings:&; Is an address operator. Is the address of the variable a.

2. Different usage: int x; in the declaration; ? X is an integer.

In the statement,&; X is the address of the integer X. It is not a pointer, there is only one&; .

In the statement, x is the value of the integer X.

3. Different pointing: * is the pointer operator, *p is the content in the storage unit pointed by the pointer variable P. Generally, only the address is stored in the pointer variable P, and * represents a pointer, for example, int * p;; -p is a pointer to an integer.

In the statement, *p represents the value of the integer pointed by the pointer.

In the statement, p stands for the address pointed by the pointer.

Statement, without &; P form, if p is a pointer.

Extended data

* null pointer, * wildcard pointer

After assigning a value to the pointer inside the function, after the function is executed, the pointer becomes an empty pointer (the variable pops up from the stack). But pointers allocated by dynamic address (heap space) will not have the above problems.

The pointer to free memory after free(p) is a wildcard pointer.

A pointer is a reference to a data object or function. Pointers can be used for many purposes, such as defining "address call" functions, and it can also implement dynamic data structures, such as linked lists and trees.

Usually, an effective way to manage a large amount of data is not to directly process the data itself, but to use pointers to the data. For example, if you need to sort a large number of large records, sorting the list of pointers to records is much more efficient than sorting records directly, because there is no need to move data in memory.

Similarly, if you need to pass a large record to a function, it is more economical to pass a pointer to the record than to pass the record itself directly, even if the function does not need to modify the record.

Pointers represent the address and type of an object or function. If an object or function has a T type, the pointer to it has a derived pointer to the T type.

For example, if var is a floating-point variable, then the expression &; Var (whose value is the address of the float variable) belongs to the pointer type pointing to the float, that is, the float* type expressed in C language.

Pointers to any type of t are also called t points for short. Therefore,&; The address operator in var generates a floating-point pointer.

Because var has not moved its position in memory, the expression &; Var is a const pointer. However, C also allows the use of pointer types to define variables. A pointer variable stores the address of another object or function.

We will discuss pointers to arrays and functions further later. First, look at how to declare a pointer to a non-array object. The syntax is as follows:

Type *[ type qualifier list] Name [= initializer];

In the statement, an asterisk (*) means "pointer". The identifier "name" is declared as an object with an object type of "type", that is, a pointer to "type". The type qualifier is optional and can contain any combination of const, volatile and restrict.

reference data

Baidu encyclopedia-pointer