首页 > 解决方案 > C中函数名前的*是什么意思?

问题描述

*在函数名前面放一个究竟是什么意思?

另外,这两个代码有何不同?

int *modify_array(int *array, int size);

int (*modify_array)(int *array, int size);

标签: cfunction-pointers

解决方案


// 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;

推荐阅读