当前位置:网站首页>The concept of C language pointer
The concept of C language pointer
2022-07-03 07:28:00 【*Thousands of miles of mountains and rivers*】
Catalog
Two 、 The four elements of the pointer
3、 ... and 、 Pointers and pointer variables
5、 ... and 、 Pointer arithmetic
6、 ... and 、 The function of the pointer
7、 ... and 、 Reference resources
One 、 The concept of pointer
To facilitate access to the contents of memory , We give each memory unit a number , This number is called address or pointer .
- The pointer has directivity , Memory address for storing other variables .
- The pointer is the address , The address is the pointer . Essentially, it is a nonnegative integer with limited operation
- A pointer is a data type , So pointers have their own memory , What's stored is the address ( Number ).
- The pointer is a variable , The variable used to hold the address , There are types .
- System (32 Bit or 64 position ) All pointer sizes in are the same
- Pointer and pointer variable are two different concepts
- A pointer is a variable with a pointer
- The secondary pointer refers to the space where the primary pointer of the same type is stored ,
- Multi level analogy. The pointer storage space of the previous level is pointed to as the second level points to the first level
Two 、 The four elements of the pointer
- The type of the pointer itself Remove the pointer name , The rest is the type of the pointer itself
- The type pointed to by the pointer Remove the pointer name and a *, The rest is the type pointed to by the pointer
- The memory of the pointer itself is used to store a number (32 Bit system occupies 4 Bytes ,64 Bit system occupies 8 Bytes )
- The memory that the pointer points to It can be all kinds of , Point to the starting address
3、 ... and 、 Pointers and pointer variables
- Pointer and pointer variable are two different concepts , But here's the thing , Usually, when we describe, we will abbreviate pointer variables as pointers .
- The pointer is the address , The address is the pointer , It is a shape unsigned integer , An integer , Its size depends on whether the system is 16 32 still 64 Bit 16/8=2byte 32/8=4byte 64/8=8byte.
- Pointer variable is actually a variable , Only the content stored is the address , Such as int* p, This p It's the pointer type , Its value is stored in the address .
After the pointer is referenced, the value of the variable corresponding to the address is obtained .
The secondary pointer is a pointer to the address of the primary pointer

1、p Is the name of a pointer variable , Indicates the memory address pointed to by this pointer variable , If you use %p To output , It will be a 16 Hexadecimal number
2、*p Indicates the contents stored in the memory address pointed to by this pointer , Generally, it is a variable or constant consistent with the pointer type .
3、 & Is the address operator ,&p It's just a pointer p The address of .
&p What is it with p What's the difference? ?
p and &p The difference is the pointer p It is also a variable , Since it's a variable , The compiler must allocate memory addresses for it , Both ordinary variables and pointer variables have an address in memory , It's like the program defines a int Type variables i, The compiler should allocate a piece of memory space for it sample .
&p Indicates that the compiler is a variable p Allocated memory address , and p Is a pointer variable , This special identity doomed it to point to another memory address , The programmer makes it point to a memory address according to the needs of the program , The memory address it points to is used p Express . and ,p The content in the address pointed to is used *p Express
Four 、 The type of pointer
- Basic types :int 、short、long、float 、double、char, Such as int *p;// Means to define a pointer , This pointer points to the integer variable , This pointer will store the address of the integer variable .
- Array pointer :** The pointer points to an array ,int (*a)[10]; // Indicates that the pointer points to a int The length of the type is 10 Array of
- A function pointer :** Pointer to a function ,void (*a)();// Indicates that the pointer points to a function with no parameters and no return value
5、 ... and 、 Pointer arithmetic
1、 Fetch address operator &
- Format :& Variable name
- meaning : Take out the address where the variable is stored
- purpose : Pass variable values across functions ( Novices can ignore it for the time being )
2、 Indirect operators *
- Format :* Pointer name / Address name
- meaning : Take out the corresponding value stored in the address
3、 Pointer set declaration
- Declaration format
- int * pi
- char * p
* notes Contains a & And a *, The two are reciprocal operations .& Get the memory address of the variable ,* Get the contents of the variable pointed to by the pointer .
6、 ... and 、 The function of the pointer
C Using pointers in languages can :
- Easy to use strings
- Effectively represent complex data structures
- Dynamic memory allocation
- Get more than one function return value
7、 ... and 、 Reference resources
- c Summary of language pointer knowledge points
- C language knowledge : Arrays and pointers
- C Summary of language pointer knowledge points - Love code network
- Simberta blog -CSDN Blog _c Summary of language pointer knowledge points
边栏推荐
- The underlying mechanism of advertising on websites
- Sorting, dichotomy
- Homology policy / cross domain and cross domain solutions /web security attacks CSRF and XSS
- Advanced API (multithreading)
- 691. Cube IV
- Read config configuration file of vertx
- Chapter VI - Containers
- 你开发数据API最快多长时间?我1分钟就足够了
- 不出网上线CS的各种姿势
- [plus de détails] dernière entrevue complète redis (50)
猜你喜欢

3311. 最长算术

Various postures of CS without online line

你开发数据API最快多长时间?我1分钟就足够了

691. Cube IV

Recursion, Fibonacci sequence

Take you through the whole process and comprehensively understand the software accidents that belong to testing

The embodiment of generics in inheritance and wildcards

Use of file class
![[solved] sqlexception: invalid value for getint() - 'Tian Peng‘](/img/bf/f6310304d58d964b3d09a9d011ddb5.png)
[solved] sqlexception: invalid value for getint() - 'Tian Peng‘

4279. 笛卡尔树
随机推荐
Leetcode 213: 打家劫舍 II
3311. Longest arithmetic
The babbage industrial policy forum
Chrome 98 Private Network Access problem w/ disabled web security: Request had no target IP address
Common analysis with criteria method
4EVERLAND:IPFS 上的 Web3 开发者中心,部署了超过 30,000 个 Dapp!
Beginners use Minio
Vertx metric Prometheus monitoring indicators
docket
The embodiment of generics in inheritance and wildcards
PgSQL converts string to double type (to_number())
Talk about floating
Sent by mqtt client server of vertx
《指環王:力量之戒》新劇照 力量之戒鑄造者亮相
Advanced API (character stream & net for beginners)
TreeMap
Common problems in io streams
Warehouse database fields_ Summary of SQL problems in kingbase8 migration of Jincang database
Arduino 软串口通信 的几点体会
Docker builds MySQL: the specified path of version 5.7 cannot be mounted.