首页 > 其他分享 >typedef函数指针用法

typedef函数指针用法

时间:2022-08-31 16:14:38浏览次数:42  
标签:typedef return int 用法 char pf PF 函数指针

int (*pf)(char *)是声明了一个名为pf的指针变量,这个指针要指向的是“parameter为char *,返回值为int类型”的函数,若要赋值,如下:

#include <stdio.h>
int (*pf)(char *);
int mprint(char *s) {
    printf("test: %s\n", s);
    return 0;
}
int main() {
    pf = mprint;
    (*pf)("zwy");
    pf("zwy");
    return 0;
}

typedef可以定一个一个函数指针类型(暂且如此表述)

#include <stdio.h>
typedef int (*PF)(char *);
int mprint(char *s) {
    printf("test: %s\n", s);
    return 0;
}
int main() {
    PF pf = mprint;
    (*pf)("zwy");
    pf("zwy");
    return 0;
}

可以理解成typedef int (char *) *PF,定义了一个数据类型PF,该数据类型是指向“parameter为char *,返回值为int类型”的函数的指针类型。

标签:typedef,return,int,用法,char,pf,PF,函数指针
From: https://www.cnblogs.com/zwyyy456/p/16643413.html

相关文章

  • HtmlAgilityPack-xpath用法
    <divclass="m-repbox"><!--/html/body/div--><divclass="m-repbodyfirstPage"><!--/html/body/div/div--><divclass="t1">基本信息</div><divclass="g-tt......
  • 区别 chown和chmod的用法
    本人总是习惯使用chmod,而把chown混淆。chown就是修改第一列内容的,chmod是修改第3,4列内容的。chown用法用来更改某个目录或文件的用户名和用户组的chown用户名:组名......
  • SQL9 - 查找除复旦大学的用户信息 - NOT IN("")和<>等用法
    题目链接戳这里题解SELECTdevice_id,gender,age,universityFROMuser_profileWHEREuniversity!="复旦大学"#Or--WHEREuniversityNOTIN("复旦大学")......
  • assert断言的用法
    assert用于:防御性编程、程序逻辑检测s_age=input("请输入你的年龄:")age=int(s_age)assert20<age<80,"年龄错误"print("正确")print("ok")如果assert后......
  • 11 个需要避免的 React 错误用法
    11个需要避免的React错误用法王平安​lovecoding,lovelife~​关注他 4人赞同了该文章随着React越来越受欢迎,React开发者也越来越......
  • 页面滚动到指定位置——js中scrollIntoView()的用法
    element.scrollIntoView()参数默认为true1.什么是scrollIntoView?scrollIntoView是一个与页面(容器)滚动相关的API2.如何调用?element.scrollIntoView()参数默认为true参......
  • 变长结构体中char data[0]的用法
    一、用法typedefstruct{intlength;chardata[0];}Header;在结构中,data是一个数组名,但该数组没有元素,该数组的真实地址紧随结构体Header之后,而这个地址就......
  • C++ lower_bound/upper_bound用法解析
    1.作用          lower_bound和upper_bound都是C++的STL库中的函数,作用差不多,lower_bound所返回的是第一个大于或等于目标元素的元素地址,而upper_bound则是返......
  • cp {,bak}用法(转载)
    cpfilename{,bak}cpfilename{,.bak}这个命令是用来把filename备份成filename.bak的等同于命令cpfilenamefilename.bak这里利用的是bash的braceexpansion(大......
  • requestAnimationFrame简单用法
    面试题:用js实现一个无限循环的动画。首先想到的是定时器<!doctypehtml><htmllang="en"><head><title>Document</title></head><body><divid="aaa"></div><......