当前位置:网站首页>Why can void * be a general pointer
Why can void * be a general pointer
2022-07-03 08:15:00 【The east wind blows the Willows】
First , The way void * Previous solutions :char * stay void Type acts as a general pointer before it comes out , however ASCII It specifies void keyword , Then for general pointers ,void * Instead of char *, But you can still use char * understand void * .
then , from char * Analyze... From an angle , because char It is the most basic memory unit in a computer (8 bit), So any other type is char Integer multiple , So any type of pointer is assigned to char * After that, it will be correctly truncated to the first memory address of the original type , And reinterpretation will not bring errors to the original data type .
Then come to the core principle :
(1) During the life cycle of the original pointer , Convert it to char * Belongs to equal size conversion , in other words , The size of any pointer is equal .
(2)char * What is saved is the first memory address of the original object , This value is equal to the value saved by the original pointer object .
(3) During the life cycle of the original pointer , Will be converted to char * Re convert to the original pointer object , It will still be the original .
Come to a conclusion :char * It can be used as a general pointer , void * It can be used as a general pointer .
tips: For pointer ,ANSI C The standard specifies its assignment constraints ( Include initialization ):
1. Both operands are compatible pointers to finite determiners or infinite operators ;
2. The type pointed to by the pointer to the operand must have all qualifiers of the type pointed to by the right operand pointer ( The qualifier of the left operand can be more ).
边栏推荐
- Use filechannel to copy files
- PIP uses image website to solve the problem of slow network speed
- Unity dotween sequence animation replay problem.
- P2622 关灯问题II(状态压缩 搜索)
- 璞华PLM为全场景产品生命周期管理赋能,助力产品主线的企业数字化转型
- VMware virtual machine configuration static IP
- Xlua task list youyou
- Encoding and decoding of golang URL
- Abstract classes and interfaces
- [untitled]
猜你喜欢
随机推荐
regular expression
Pulitzer Prize in the field of information graphics - malofiej Award
Idea dereference display effect
About the problem that the editor and the white screen of the login interface cannot be found after the location of unityhub is changed
Demonstration of plug-in use of ventuz basic series
Docker installs MySQL and successfully uses Navicat connection
Ilruntime learning - start from scratch
一个实习生的CnosDB之旅
Oracle insert single quotation mark
Wechat native applet cloud development learning record 01
Go resolve ID card
Wechat applet taro learning record
十六进制编码简介
Open the influence list of "National Meteorological Short Videos (Kwai, Tiktok) in November" in an interactive way“
jsutlis
Un système de gestion de centre commercial pour la conception de cours de technologie d'application de base de données
P2622 关灯问题II(状态压缩 搜索)
JS common basic case sorting (continuous update)
Base64和Base64URL
One dimensional array two dimensional array (sort Max insert sort)









