c - C中函数名前的*是什么意思?
问题描述
*
在函数名前面放一个究竟是什么意思?
另外,这两个代码有何不同?
int *modify_array(int *array, int size);
int (*modify_array)(int *array, int size);
解决方案
// declares a function which returns an int (usually 4 bytes)
int modify_array_1(int *array, int size);
// declares a function which returns an pointer (usually 8 bytes)
// that pointer is the memory address of a 4-byte int
int *modify_array_2(int *array, int size);
// declares a variable of type pointer (usually 8 bytes) which points to a function
// the function has the signature int SOMETHING(int *array, int size)
int (*modify_array_3)(int *array, int size);
// now, because modify_array_1 has that signature, you can run this:
modify_array_3 = modify_array_1;
推荐阅读
- django - 即使在处理成功并且没有返回 Http 响应之后,Gunicorn 工作人员也会超时
- spring-boot - 从 Angular 连接到 Spring Boot 时出现 CORS 策略问题
- regex - 尝试使用正则表达式模式从配置文件中提取用户名和密码时出现问题
- c# - 性能:绑定与代码隐藏
- angular - 如何在 ionic 5 中添加日期选择器
- python - 从字典散点图中绘制元组值
- angular - Karma 测试用例未在 Angular11 中运行
- wordpress - 使用自定义分类术语和类别显示帖子
- c++ - 有没有办法检测输入的整数是否是字符串?
- python - 检查 Series 是否包含列表中的任何元素