define 实例

// ----------------------------------------------define-------------------------------------

// #define 常量名 代替值

// 定义字符串常量

#define MY_STR "it is a string"

// 定义常量

#define PI 3.1415926

#define TWO_PI 2*PI

// 定义宏 (使用参数)

#define sumValue(x,y) (x+y)

#define chengValue(x,y) (x*y)

// #  ##

// #代表:将宏参数转换成字符串

// ##代表:将##左右的标识符连接成一个,但不是字符串

#define to_str(x) #x

#define lianjie(x) MY_STR#x

    NSLog(@"mystri is:%s", MY_STR);

    NSLog(@"PI IS :%f", PI);

    NSLog(@"TWO PI IS : %f", TWO_PI);

    NSLog(@"sumValue value IS : %.2f", sumValue(3.526,PI)); // 保留2位小数位

    NSLog(@"cheng value IS : %i", chengValue(3,4));

    NSLog(@"lianjie IS : %s", lianjie(123654)); // lianjie IS : it is a string123654

    NSLog(@"tostr IS : %s", to_str(ceshi)); // tostr IS : ceshi

原文地址:https://www.cnblogs.com/xiangjune/p/4898552.html