What is the function of pointers in C language

王林
Release: 2020-11-12 16:39:34
Original
16949 people have browsed it

The function of pointers in C language is: not only can the data itself be operated through the pointer, but also the variable address where the data is stored can be operated. Pointers are memory addresses, and pointer variables are variables used to store memory addresses.

What is the function of pointers in C language

Pointer definition:

Pointer is an important concept and feature in C language, and it is also a difficult part of mastering C language. Pointers are memory addresses. Pointer variables are variables used to store memory addresses. Different types of pointer variables occupy the same storage unit length, while variables that store data occupy different lengths of storage space depending on the type of data. different. With pointers, you can not only operate on the data itself, but also on the variable address where the data is stored.

(Related learning recommendations: java video tutorial)

The pointer is the relative distance value of an entity occupying storage space from the starting position of this space. In C/C language, pointers are generally considered to be pointer variables. The content of a pointer variable stores the first address of the object it points to. The object pointed to can be a variable (pointer variables are also variables), arrays, functions, etc. occupy storage space. entity.

Define pointer variables:

Defining pointer variables is very similar to defining ordinary variables, but you need to add an asterisk * in front of the variable name, the format is:

datatype *name;
Copy after login

or

datatype *name = value;
Copy after login

* indicates that this is a pointer variable, and datatype indicates the type of data pointed to by the pointer variable. For example:

int *p1;
Copy after login

p1 is a pointer variable pointing to int type data. As for which data p1 points to, it should be determined by the value assigned to it. Another example:

int a = 100;
int *p_a = &a;
Copy after login

Initialize the pointer variable p_a while defining it, and assign the address of variable a to it. At this time, p_a points to a. It is worth noting that p_a requires an address, and the address character & must be added in front of a, otherwise it will be incorrect.

Related recommendations: php training

The above is the detailed content of What is the function of pointers in C language. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template