How to get the address of a variable in Swift

1 Answer

0 votes
func printAddress<T>(of pointer: UnsafePointer<T>) {
    print(pointer)
}

var x = 42

withUnsafePointer(to: &x) { print($0) }

printAddress(of: &x)




/*
run:

0x0000559eda971180
0x0000559eda971180

*/

 



answered Nov 4, 2022 by avibootz

Related questions

1 answer 99 views
1 answer 155 views
155 views asked Jan 22, 2025 by avibootz
1 answer 154 views
154 views asked Nov 4, 2022 by avibootz
1 answer 131 views
1 answer 220 views
2 answers 132 views
...