Array memory address

Please help me. I am completely confused at this memory address.

NSMutableArray *arr = [[NSMutableArray alloc]initWithObjects:@"1",@"2",@"3", nil]; NSLog(@"Address of array = %p",&arr); NSLog(@"Array element Address = %p",arr); NSLog(@"Address 0th element %p",[arr objectAtIndex:0]); NSLog(@"Address of array =%lx",(long)&arr); NSLog(@"Array element Address = %lx",(long)arr); NSLog(@"Address 0th element %lx",(long)[arr objectAtIndex:0]); **Output** Address of array = 0xbfffd804 Array element Address = 0x866f340 Address 0th element 0x4748 Address of array =bfffd804 Array element Address = 866f340 Address 0th element 4748 

I get this conclusion, but they confuse me with the second and third output, because, according to my knowledge, the second and third output should be the same. So please, anyone can explain to me. Thanks in advance.

+6
source share
1 answer

If it was a simple C array, you might be right, but your arr is an instance of the class, not the base address of any data structure that NSMutableArray uses to store its objects (which is probably not a simple C array, either).

+4
source

All Articles