C语言函数指针用法

#include <stdio.h>
#include <string.h>

static void sayHello();
static void salute();

void sayHello(){
    const char *m = "func_pointer\n";
    printf(m);
    printf("%d\n", strlen(m));
}

void salute(){
    printf("I love ella\n");
}

int main(int argc, char **argv){
    printf("%d\n", argc);
    void (*func)();
    if(argc == 1)
        func = sayHello;
    else
        func = salute;
    (*func)();
}

 

posted @ 2017-10-16 00:48  涉谷猫猫  阅读(124)  评论(0编辑  收藏  举报