的typedef INT(* PF)需要解释 [英] typedef int (*pf) needs explaining

查看:166
本文介绍了的typedef INT(* PF)需要解释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一般情况下,我们使用的typedef 来获取备用名称的数据类型。
例如 -

 的typedef长整型里; //李可代替长整型现在使用

但是,什么是下面的typedef吗?

 的typedef INT(* PF)(INT,INT);


解决方案

 的typedef INT(* PF)(INT,INT);

这意味着与 PF 类型声明的变量都指向这需要两个 INT 参数,并返回一个函数一个 INT

在换句话说,你可以做这样的事情:

 的#include<&stdio.h中GT;的typedef INT(* PF)(INT,INT);INT addUp(int类型的,INT B){返回A + B; }诠释主要(无效){
    PF = XYZZY addUp;
    的printf(%d个\\ N,XYZZY(19,23));
    返回0;
}

Generally, we use typedef to get alternate names for datatypes. For example --

typedef long int li; // li can be used now in place of long int

But, what does the below typedef do?

typedef int (*pf) (int, int);

解决方案

typedef int (*pf) (int, int);

This means that variables declared with the pf type are pointers to a function which takes two int parameters and returns an int.

In other words, you can do something like this:

#include <stdio.h>

typedef int (*pf)(int,int);

int addUp (int a, int b) { return a + b; }

int main(void) {
    pf xyzzy = addUp;
    printf ("%d\n", xyzzy (19, 23));
    return 0;
}

这篇关于的typedef INT(* PF)需要解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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