美文网首页
关于static与#define的实例.

关于static与#define的实例.

作者: 品评 | 来源:发表于2018-07-26 16:39 被阅读0次

关于static与#define的实例.

#import <Foundation/Foundation.h>

#define XMGAccount @"account"
#define XMGAccount1 @"account1"
static NSString * const account = @"account";
static NSString * const account1 = @"account1";
static const NSString *account4 = @"account";

int main(int argc, char *argv[]) {
    @autoreleasepool {
    
        NSLog(@"XMGAccount %p",XMGAccount);
        NSLog(@"XMGAccount1 %p",XMGAccount1);
        NSLog(@"account %p",account);
        NSLog(@"account1 %p",account1); 
        NSString *account2 = @"account";
        NSString *account3 = @"account";
        NSLog(@"account2 %p",account2);
        NSLog(@"account3 %p",account3);
        NSLog(@"account4 %p",account4);
        
    }
}

输出为

2018-07-25 19:05:58.444 Test[29791:2541706] XMGAccount 0x10641d048
2018-07-25 19:05:58.445 Test[29791:2541706] XMGAccount1 0x10641d068
2018-07-25 19:05:58.445 Test[29791:2541706] account 0x10641d048
2018-07-25 19:05:58.445 Test[29791:2541706] account1 0x10641d068
2018-07-25 19:05:58.445 Test[29791:2541706] account2 0x10641d048
2018-07-25 19:05:58.445 Test[29791:2541706] account3 0x10641d048
2018-07-25 19:05:58.445 Test[29791:2541706] account4 0x10641d048

通过上面的实例发现字符串里面的数据如果是一样的不管实例化的对象是什么都是同一个地址.

相关文章

网友评论

      本文标题:关于static与#define的实例.

      本文链接:https://www.haomeiwen.com/subject/znibmftx.html