#import <Foundation/Foundation.h>
int sum(int value1, int value2)
{
return value1 + value2;
}
int minus(int value1, int value2)
{
return value1 - value2;
}
// 给指向函数的指针起别名
typedef int (*calculte)(int, int);
// 注意: 利用typedef给block起别名, 和指向函数的指针一样, block变量的名称就是别名
typedef int (^calculteBlock)(int , int);
int main(int argc, const char * argv[]) {
/*给指向函数的指针起别名
// int (*sumP)(int, int);
// sumP = sum;
calculte sumP = sum;
NSLog(@"sum = %i", sumP(20, 10));
// int (*minusP)(int, int);
// minusP = minus;
calculte minusP = minus;
NSLog(@"minus = %i", minusP(20, 10));
*/
//给Block起别名
// int (^sumBlock)(int , int );
calculteBlock sumBlock = ^(int value1, int value2){
return value1 + value2;
};
NSLog(@"sum = %i", sumBlock(20, 10));
// int (^minusBlock)(int , int);
calculteBlock minusBlock = ^(int value1, int value2){
return value1 - value2;
};
NSLog(@"minus = %i", minusBlock(20, 10));
return 0;
}
网友评论