關(guān)于static與#define的實(shí)例.

關(guān)于static與#define的實(shí)例.

#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

通過上面的實(shí)例發(fā)現(xiàn)字符串里面的數(shù)據(jù)如果是一樣的不管實(shí)例化的對(duì)象是什么都是同一個(gè)地址.

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容