C语言指针函数
迪丽瓦拉
2025-05-31 13:05:34
0

typedef int (*PFunc)(int);

去掉 typedef ,得到正常变量声明=> int (*PFunc)(int);

变量 PFunc 的类型为一个函数指针,指向的返回值类型为 int,参数类型为 int 的函数

原型;

"typedef int (*PFunc)(int)"中 PFunc是函数指针类型(该指针类型指向返回值类型为

int,参数类型为 int 的函数)的一个 typedef-name。

PFunc fptr; <=> fptr 是一个 pointer to function with one int parameter, returning int

#include "iostream"

using namespace std;

int add(int a,int b){

return (a+b);

}

typedef int (* func)(int ,int ) ;

void main(){

func f = add;

int n = f(1,2);

cout << n << endl;

}


typedef int* Func(int);

去掉 typedef ,得到正常变量声明=> int* Func(int);

变量 Func 的类型为一个函数标识符,该函数返回值类型为 int*,参数类型为 int;

"typedef int* Func(int)"中 Func 是函数类型(函数返回值类型为 int*,参数类型为 int)

的一个 typedef-name。

Func *fptr; <=> fptr 是一个 pointer to function with one int parameter, returning a

pointer to int

Func f; 这样的声明意义就不大了。

相关内容