static、__block、代码块递归的学习

一.递归:
static int jabezAge = 17;
static void (^defineBlock5)(void) = ^(void) {
if( jabezAge > 0 ){
NSLog( @"myAge is %i", jabezAge-- );
defineBlock5();
}
};
defineBlock5();
二.块
1.typedef double (^plusTypedef)(double a, double b);
plusTypedef defPlus = ^(double a, double b) {
return a+b;
};函数

NSLog( "%.2f, %.2f", defPlus( 3, 4 ), defPlus( 4 , 6)  );        NSLog( "鏁扮粍鎺掑簭: array2 %@", array2 );
2.int (^plusNumber)(int, int);"%.2f, %.2f", defPlus( 3, 4 ), defPlus( 4 , 6)  );        NSLog(
plusNumber  = ^(int number1 , int number2 ){
__block int flag = 0; mber1 > number2 ? number1 : number2;
           };
三.static
全局变量:可放在main前定义,多个函数体可应用以同时

3.代码块main函数实现加减乘除code

typedef double (^numberBlock)(double a, double b);

    numberBlock addBlock=^(double a, double b){
        return a+b;
    };
    numberBlock subBlock=^(double a,double b){
        return a-b;
    };
    numberBlock mulBlock=^(double a, double b){
        return a*b;
    };
    numberBlock divBlock=^(double a,double b){
        return a/b;
    };
    NSLog(@"%f",addBlock(8.8,2.2));
    NSLog(@"%f",subBlock(8.8,2.2));
    NSLog(@"%f",mulBlock(8.8,2.2));
    NSLog(@"%f",divBlock(8.8,2.2));
相关文章
相关标签/搜索