int age = 10;
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
int a = 100;
NSLog(@"数据段:age %p",&age); //数据段:age 0x100008208
NSLog(@"栈:a %p",&a); //栈:a 0x7ffeefbff41c
NSLog(@"堆:obj %p",[[NSObject alloc]init]);//堆:obj 0x1080043d0
NSLog(@"class %p",[GHPerson class]);//class 0x1000081b0
}
return 0;
}
我们也可以通过此种方式判断当前变量或者对象是在内存存储的哪个区域。如果某个无法具体判断比如:
NSLog(@“class %p”,[GHPerson class]);//class 0x1000081b0
我们可以看到其打印结果和
NSLog(@“数据段:age %p”,&age); //数据段:age 0x100008208
内存地址比较接近,所以可以考虑是在同一个区域进行存储。