⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 passptr.c

📁 里面包含很多c语言的源码
💻 C
字号:
/* Passing a pointer to a function as an argument. */

#include <stdio.h>

/* The function prototypes. The function func1() takes as */
/* its one argument a pointer to a function that takes no */
/* arguments and has no return value. */

void func1(void (*p)(void));
void one(void);
void two(void);
void other(void);

int main( void )
{
    /* The pointer to a function. */
    void (*ptr)(void);
    int nbr;

    for (;;)
    {
        puts("\nEnter an integer between 1 and 10, 0 to exit: ");
        scanf("%d", &nbr);

        if (nbr == 0)
            break;
        else if (nbr == 1)
            ptr = one;
        else if (nbr == 2)
            ptr = two;
        else
            ptr = other;
        func1(ptr);
    }
    return 0;
}

void func1(void (*p)(void))
{
    p();
}

void one(void)
{
    puts("You entered 1.");
}

void two(void)
{
    puts("You entered 2.");
}

void other(void)
{
    puts("You entered something other than 1 or 2.");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -