[C基础知识]2015-09-24

//  main.c
//  demoC-15
//
//  Created by apple on 15/9/24.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#include <stdio.h>

int demoFunc();

int *demoFunc2(); //指针函数

void demoFunc3(int a); //带一个参数的函数,无返回值

void (*pFunc)(int) = demoFunc3; // 函数名等价于函数的入口地址,pFunc指向函数

int demoFunc4(int a,int b,int (*c)(int a,int b));  // int (*c)(int,int) 指向函数的指针
int customMax(int a,int b);
int customMuti(int,int);

int main(int argc, const char * argv[]) {

#if 0
    int result = demoFunc();
    printf("result:%d\n",result);
#endif

//    int array[3] = {99,88,77};
//    int *pa = array;
#if 0
    int *result = demoFunc2();
    int array[10] = {9,6};
    printf("result:%d\n",*result);
#endif

#if 0
    demoFunc3(56);

#endif

#if 0
    demoFunc3(77);
    pFunc(77);
#endif
    int a = 30,b = 90;
//    int result = demoFunc4(a, b, customMax);
    int result = demoFunc4(a, b, customMuti);
    printf("%d\n",result);


    return 0;
}

int demoFunc()
{
    return 5;
}

int *demoFunc2() //指针函数的定义(实现)
{
    static int array[5] = {11,22,33,44,55};
    return array;
}
void demoFunc3(int a)
{
    printf("a = %d\n",a);
}

int customMax(int a,int b)
{
    return a>b?a:b;
}
int customMuti(int a,int b)
{
    return a*b;
}
int demoFunc4(int a,int b,int (*c)(int a,int b))
{
    int maxValue = c(a,b);
    return maxValue/2;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值