关于返回指针的函数与指向函数的指针

返回指针的函数

//作者:mike
//时间:2020,08,21
//目的:关于返回指针的函数

#include<stdio.h>
#include<malloc.h>

int* func(int a, int b)
{
    int* p = (int*)malloc(sizeof(int));
    *p = a + b;
    return p;
};

int main()
{
    int* point = func(11,22);
    //输出16 进制数。
    //%x, %o, %d
    printf("the address of point is: %x
", point);
    printf("the content of the point is :%d", *point);
    free(point);
    getchar();

    return 0;
}

指向函数的指针,这其实只是一个指针

//作者: mike
//时间: 2020,08,21
//目的:关于指向函数的指针

#include<stdio.h>

//函数的声明
int func(int , int );
int (*f)(int , int );
int (*f1)(int , int );

int main()
{
    int re;
    //两种方式是等价的
    f = func;
     f1 = &func;
     re = f(1,2);
    printf("%d
",re);
   printf("%d",f1(11,22));
    return 0;
};

int func(int a, int b)
{
    return a + b;
}
原文地址:https://www.cnblogs.com/zijidefengge/p/13539684.html