编辑代码

#import <Foundation/Foundation.h>  
  
int main(int argc, const char * argv[]) {  
    @autoreleasepool {  
        // 声明一个指向整数的指针变量  
        int *integerPointer;  
          
        // 声明一个整数变量并初始化  
        int myInteger = 42;  
          
        // 让指针变量指向整数变量  
        integerPointer = &myInteger;  
          
        // 输出指针变量存储的地址  
        NSLog(@"Address of myInteger: %p", &myInteger);  
          
        // 输出指针变量指向的值  
        NSLog(@"Value pointed by integerPointer: %d", *integerPointer);  
          
        // 修改指针指向的值  
        *integerPointer = 100;  
          
        // 输出修改后的值  
        NSLog(@"New value of myInteger: %d", myInteger);  
          
        // 声明一个指向 NSString 对象的指针变量  
        NSString *stringPointer;  
          
        // 创建一个 NSString 对象并让指针指向它  
        stringPointer = @"Hello, World!";  
          
        // 输出指针指向的字符串对象  
        NSLog(@"String pointed by stringPointer: %@", stringPointer);  
          
        // 声明另一个指向 NSString 对象的指针变量,并让它指向相同的对象  
        NSString *anotherStringPointer = stringPointer;  
          
        // 输出另一个指针指向的字符串对象,应该和上面的输出一样  
        NSLog(@"String pointed by anotherStringPointer: %@", anotherStringPointer);  
          
        // 比较两个指针是否指向同一个对象  
        if (stringPointer == anotherStringPointer) {  
            NSLog(@"stringPointer and anotherStringPointer point to the same object");  
        } else {  
            NSLog(@"stringPointer and anotherStringPointer do not point to the same object");  
        }  
    }  
    return 0;  
}