Skip to content

Commit ae88e32

Browse files
committed
Add new example for Reviews
1 parent 719e7f8 commit ae88e32

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

3 files changed

+21
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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

0 commit comments

Comments
 (0)