函数 结构体 指针

参考地址:http://blog.csdn.net/ysdaniel/article/details/6667204

//============================================================================
// Name : objc.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C, Ansi-style
//============================================================================

#include
<assert.h>
#include
<ctype.h>
#include
<errno.h>
#include
<limits.h>
#include
<string.h>
#include
<stdarg.h>
#include
<stdlib.h>
#include
<stdio.h>

struct DEMO
{
int x, y;
int (*func)(int, int); //函数指针
};

int add2(int x, int y)
{
return x + y;
}

int main() {
struct DEMO demo;
demo.func
= &add2; //结构体函数指针赋值
printf("%d", demo.func(3, 4));
return 1;
}

  

原文地址:https://www.cnblogs.com/wangkangluo1/p/2155660.html