Please help me out. I'm totally confused about in this memory address.
NSMutableArray *arr = [[NSMutableArray alloc]initWithObjects:@"1",@"2",@"3", nil];
NSLog(@"Address of array = %p",&arr);
NSLog(@"Array's element Address = %p",arr);
NSLog(@"Address 0th element %p",[arr objectAtIndex:0]);
NSLog(@"Address of array =%lx",(long)&arr);
NSLog(@"Array's element Address = %lx",(long)arr);
NSLog(@"Address 0th element %lx",(long)[arr objectAtIndex:0]);
**Output**
Address of array = 0xbfffd804
Array's element Address = 0x866f340
Address 0th element 0x4748
Address of array =bfffd804
Array's element Address = 866f340
Address 0th element 4748
I'm getting this output but i'm confused with second and third output because according to my knowldge second and third output should be same. So please any one can explain me. Thanks in advance.
The memory address of the first element of an array is called first address, foundation address, or base address. Because the mathematical concept of a matrix can be represented as a two-dimensional grid, two-dimensional arrays are also sometimes called "matrices".
A memory array is a linear data structure that stores a collection of similar data types at contiguous locations in a computer's memory. Memory arrays are categorized as one-dimensional arrays and multiple-dimensional arrays. Arrays are among the oldest data structures and are used in almost every computer program.
An array stores its elements in contiguous memory locations. If You created the array locally it will be on stack. Where the elements are stored depends on the storage specification.
If this was a plain C array you might be right, but your arr
is an instance of a class, not the base address of whatever data structure NSMutableArray uses to store its objects (which is probably not a plain C array, either).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With