File tree Expand file tree Collapse file tree 3 files changed +21
-0
lines changed
03 C C++ Python R and Mojo review
03-2 Python Review/01 Pointers
03-3 R Language Review/01 Pointers
03-4 Mojo Review/01 Pointers Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 1+ # In Python, variables are references to objects, so no explicit pointers are required
2+
3+ x = 10
4+ ptr = x # 'ptr' references the same value as 'x'
5+
6+ # Python doesn't expose memory addresses directly, but we can use id() to get the memory address.
7+ print (f"Address of x: { id (ptr )} " ) # Prints the memory address (not exactly like C)
8+ print (f"Value of x: { ptr } " ) # Prints the value of x
Original file line number Diff line number Diff line change 1+ x <- 10
2+ ptr <- x # In R, variables are references
3+
4+ # R doesn't have a direct way to show memory addresses, but you can use the "address" of an object
5+ # using the "pryr" package for low-level memory inspection
6+ library(pryr )
7+ cat(" Address of x: " , address(ptr ), " \n " ) # Address function from pryr package
8+ cat(" Value of x: " , ptr , " \n " )
Original file line number Diff line number Diff line change 1+ x = 10
2+ ptr = & x # Address-of operator, like in C
3+
4+ print (f " Address of x: { ptr} " ) # Prints the memory address
5+ print (f " Value of x: { x} " ) # Dereferencing 'ptr' would give us the value
You can’t perform that action at this time.
0 commit comments