'Simple syntax to print out Nim address

How to print out Nim address just like in C:

 int array[] = { 7, 8, 9 };
 printf(" %p ", (void *)&array);

? the try:

 var
   arr = newSeq[array[2,int]](2)
   refVar = addr arr

 echo refVar

gave:

Error: type mismatch: got <ptr seq[array[0..1, int]]>
but expected one of: 
proc echo(x: varargs[typed, `$`])
  first type mismatch at position: 1
  required type for x: varargs[typed]
  but expression 'refVar' is of type: ptr seq[array[0..1, int]

Please help out !



Solution 1:[1]

If you just want the memory address alone (not what else repr gives you), the simplest way is:

echo cast[int](arr.addr).toHex

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Josh Girvin