内C - 功能和无效的变量类型的指针? [英] C - pointers in functions and void variable type?

查看:89
本文介绍了内C - 功能和无效的变量类型的指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请解释什么是原型这样的手段

 无效*亚军(无效*参数)


  1. 如何是一个变量类型为void?

  2. 什么是与*亚军函数名是什么意思?

  3. 是它的函数的地址?


解决方案

首先,有之间绝对没有区别无效*亚军 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)

  1. How is a variable type void?
  2. What does the function name with *runner mean?
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆