August 24, 2009

function pointer(function table)

#include <stdio.h>

typedef void (*func_ptr_t)(int);

void bar(int n)
{
    printf("bar() %d\n", n*2);
}

void foo(int n)
{
    printf("foo() %d\n", n);
}

int main(void)
{
    func_ptr_t table[] = {
        foo,
        bar,
    };
    int i;

    for (i = 0 ; i < 2 ; i++) {
        table[i](100);
    }
    system("pause");
    return 0;
}

0推薦此文章
Today's Visitors: 0 Total Visitors: 37
Personal Category: Uncategorized Articles Topic: technology / tech info / programming
[Trackback URL]

Post A Comment









Yes No



Please input the magic number:

( Prevent the annoy garbage messages )
( What if you cannot see the numbers? )
Please input the magic number

誰來收藏
Loading ...
unlog_NVPO 0