typedef void (*fun) (void);

Source: Internet
Author: User

typedef void (*fun) (void);

A function is similar to an array, and the function name is its first address;
12345678910111213141516171819202122232425262728293031 inti;             // 定义了一个int类型的变量i; 而这样typedefINTint;   // 表示用户自己定义了一个整型数据类型INT,实际上就等同于int 所以:INT ii;                   // 表示定义了一个int类型的变量ii;  void(*pFn)(void)  // 定义了一个函数指针,该函数指针指向类似于void Foo(void)函数的函数入口地址 typedefvoid(*Fun)(void                   // 表示用户自己定义了一个函数指针数据类型 Fun pf;            // 表示定义了一个函数指针pf,改函数指针指向类似于void   *pf(void)的函数  //leo char*a="This is ";// 这个在常量区分配一个空间,然后a指向此空间chara[] = "This is";                   // 这个在常量区分配一个空间,然后又在栈上分配一个空间,将常量区的内容复制过来,所以可以修改/* //////////定义一个函数指针类型/////////// *///比如你有三个函数:voidhello(void) { printf("你好!"); }voidbye(void) { printf("再见!"); }voidok(void) { printf("好的!"); }typdef void(*funcptr)(void);                   // 这样就构造了一个通用的函数;你用的时候可以这样:voidspeak(intid){   funcptr words[3] = {&hello, &bye, &ok};   funcptr fun = words[id];   (*fun)();}这样的话,如果speak(0)就会显示“你好!”speak(1)就会显示“再见!”speak(2)就会显示“好的!”用于处理参数和返回值的形式都一样,但是功能不确定的一组函数,可以使用函数指针比如算术运算符,加、减、乘、除,都可以用typedefint(*calc)(int,int)代表,等等

typedef void (*fun) (void);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.