C语言基础-2

函数指针

`
#include<stdio.h>

int add(int a, int b){
    return a + b;
}

int sub(int a, int b){
    return a - b;
}
//函数指针保存着函数的入口地址

int calc(int a, int b, int (*p)(int, int)){
    return p(a, b);
}
int main(){
    int a = 20;
    int b = 30;
    int result = 0;
    result = calc(a, b, add);

    printf("result = %d \n", result);

    result = calc(a, b, sub);

    printf("result = %d \n", result);

    return 0;
}   
`

typedef

  • typedef 是给存在类型起别名,别名和原类型完全等价

    int a;//a是一个标识符,在这是个变量名
    typedef int a;//a还是标识符,但不是变量名,而是一个int类型的别名
    
    char buf[5];//buf也是标识符,在这是个数组名
    typedef char buf[5];//buf是标识符,但不是数组名,而是一个char [5]数组类型别名
    
    struct Student{
        int id;     
    }s1;    //s1是一个结构体变量名
    
    typedef struct Stuent{
        int id;
    }s1;    //s1还是标识符,但不再是结构体变量,而是结构体类型struct Student的别名
    
    void (*pfun)(int,int *);//函数指变量名pfun
    typedef void (*pfun)(int,int *);//pfun是一个函数指针类型名
    
    pfun p;
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值