当前位置:网站首页>Void* pointer
Void* pointer
2022-06-13 08:54:00 【Human high quality Algorithm Engineer】
You can see in the code (void )stDst.pucBuf The pointer , void What is the pointer for , See below ,
void Literally, it means “ No type ”,void * Then for “ No type pointer ”,*void Can point to any type of data .( The key )
Any type of pointer can be assigned directly to void*, There is no need to cast
void *p1;
int *p2;
p1 = p2;
void *arg;
int i;
i=(int *)arg;
If you define void type :
void a;
This line will compile with an error , Even if void a There will be no errors in the compilation of , It doesn't have any practical significance either .
void It's just an abstract need , If you understand object-oriented correctly “ Abstract base class ” The concept of , And it's easy to understand void data type . Just as you can't define an instance of an abstract base class , We can't define a void Variable .
void The rules of using keywords :
1. If the function does not return a value , Then it should be declared as void type ;
2. If the function has no arguments , Then it should be declared that the parameter is void;
3. If the argument to a function can be a pointer of any type , Then it should be declared that the parameter is void * ;
4. void Can't represent a real variable ;
Here's the explanation :
void The real role is :
(1) A restriction on the return of a function ;
(2) Restrictions on function parameters .
1. If the function does not return a value , Then it should be declared as void type ;
stay C In language , Any function without return value type restriction , Will be handled by the compiler as a return integer value . But many programmers mistake it for void type . for example :
add ( int a, int b )
{
return a + b;
} // The return is int type
Of course we're writing C/C++ The program , For any function, its type must be specified one by one . If the function does not return a value , Be sure to state that void class
type . This is the need for good readability of the program , It is also the requirement of programming standardization .
2. Careful use void Pointer types
according to ANSI(American National Standards Institute) standard , Not right void Pointer for algorithm operation , The following operations are illegal :
void * pvoid;
pvoid++; //ANSI: error
pvoid += 1; //ANSI: error
//ANSI The reason why the standard is so recognized , It's because it insists on : The pointer for algorithm operation must be determined to know the size of the data type it points to .
// for example :
int *pint;
pint++; //ANSI: correct
边栏推荐
猜你喜欢
Use of grep
Problems in the deconstruction and assignment of objects, comparison between empty strings and undefined
Docker installing MySQL local remote connection docker container MySQL
0. Quelques doutes au sujet de SolidWorks
Vs installation of vassistx plug-in causes Chinese input of wpf-xaml file to be garbled. Solution
「解读」华为云桌面说“流畅”的时候,究竟在说什么?
Mapbox usage, including drawing, loading, modifying, deleting points and faces, displaying pop ups, etc
Diversified tables through TL table row consolidation
torch. How to calculate addmm (m, mat1, mat2)
Browser render passes
随机推荐
浅析Visual Studio 使用
Tensorflow1.14 corresponds to numpy version
【Pycharm踩坑记录】配置远程运行后提示,[Errno 2] No such file or directory
Object in ES6 Use of entries()
Invalid flex layout setting width
VI editor
【安全】零基礎如何從0到1逆襲成為安全工程師
turf. JS usage
VS安装VAssistX插件导致WPF-XAML文件输入中文出现乱码问题解决方案
教程篇(5.0) 01. 产品简介及安装 * FortiEDR * Fortinet 网络安全专家 NSE 5
[pychart pit stepping record] prompt after configuring remote operation, [errno 2] no such file or directory
H5 mobile terminal adaptation
centos 安装mysql及设置远程访问
14. class initialization, default constructor, =default
ES6 use of dynamic attributes
Margin:0 reason why auto does not take effect
0. some doubts about learning SolidWorks for the first time
On the use of visual studio
[leetcode weekly race record] record of the 80th biweekly race
1.SolidWorks各模块的学习顺序