内C - 功能和无效的变量类型的指针? [英] C - pointers in functions and void variable type?
问题描述
请解释什么是原型这样的手段
无效*亚军(无效*参数)
- 如何是一个变量类型为void?
- 什么是与*亚军函数名是什么意思?
- 是它的函数的地址?
首先,有之间绝对没有区别无效*亚军
和 void *的亚军
。该功能的名称是亚军
。其次,函数可以声明无效
这只是意味着它不返回任何东西。
然而,该签名是不同的。它返回一个无效*
,这仅仅意味着一个指向一个未指定的数据类型。或思考它的一个简单的方法,它返回一个内存地址。
这同样适用于在 void *的参数
,它只是接受的内存地址。
修改
这可能会使它更清楚一点:
无效FUNC(无效* PTR); //参加一个通用的内存地址,返回任何结果
void *的FUNC(无效* PTR); //参加一个通用的内存地址,返回类似
void *的FUNC(无效); //功能不带任何参数(必要C,用C ++可选)
void *的FUNC(无效参数); //无效!正如你猜到了,这将是毫无意义的。
无效* FUNC(); //在C ++ preferred语法,函数接受什么,并返回一个通用的内存地址
//在C,这意味着它需要的参数人数不详无效FUNC(); //在C ++:函数接受什么,什么都不返回
//在C:函数接受的参数人数不详,没有返回值
Please explain what a prototype like this means
void *runner(void *param)
- How is a variable type void?
- What does the function name with *runner mean?
- Is it the address of the function?
First of all, there is absolutely no difference between void* runner
and void *runner
. The function's name is runner
. Secondly, a function CAN be declared void
which simply means that it doesn't return anything at all.
However this signature is different. It returns a void*
, which simply means a pointer to an unspecified datatype. Or an easier way of thinking about it, it returns a memory address.
The same goes for the void *param
, it's just accepting a memory address.
EDIT
This might make it a bit clearer:
void func(void *ptr); // take in a generic memory address, return nothing
void *func(void *ptr); // take in a generic memory address, return similar
void *func(void); // Function takes no parameters (necessary in C, optional in C++)
void *func(void param); // Invalid! As you guessed, this would be pointless.
void *func(); // Preferred syntax in C++, function takes in nothing and returns a generic memory address
// In C this means it takes an undetermined number of arguments
void func(); // In C++: function takes in nothing, returns nothing
// In C: function takes in an undetermined number of arguments, returns nothing
这篇关于内C - 功能和无效的变量类型的指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!