I wrote some short IBM Swift Sandbox shortcodes and came across a confusing issue
I tried to get the addresses of the elements of the array:
func printMemory(ptr: UnsafePointer<Int>){
print("At memory:\(ptr)")
}
var arr: [[Int]] = [
[0,1,2,3,4],
[0,1,2],
[0]
]
printMemory(&arr[0][0])
printMemory(&arr[1][0])
And the output of this code has the same addresses.
Changing "UnsafePointer" to "UnsafeMutablePointer" will solve this problem, but I just don't know why this is happening.
Why do I get the same address first and what occupies this address?
Another issue I encountered:
Also, if I only changed the last two lines of code to:
printMemory(&arr[0])
printMemory(&arr[0][1])
.
, , , arr [0] [Int], Int UnsafePointer. .
, . , .
"UnsafeMutablePointer" printMemory(), .
, , , .
!