summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--c.html.markdown32
-rw-r--r--clojure.html.markdown3
-rw-r--r--python.html.markdown12
3 files changed, 36 insertions, 11 deletions
diff --git a/c.html.markdown b/c.html.markdown
index 15bfa05e..c23e8d2c 100644
--- a/c.html.markdown
+++ b/c.html.markdown
@@ -50,8 +50,8 @@ short x_short = 0;
char x_char = 0;
char y_char = 'y'; // Char literals are quoted with ''
-long x_long = 0; // Still 32 bytes for historical reasons
-long long x_long_long = 0; // Guaranteed to be at least 64 bytes
+long x_long = 0; // Still 32 bits for historical reasons
+long long x_long_long = 0; // Guaranteed to be at least 64 bits
// 32-bit floating-point decimal
float x_float = 0.0;
@@ -194,26 +194,42 @@ printf("%d\n", (short) 65537); // => 1 (Max short = 65535)
// Pointers
///////////////////////////////////////
-// You can retrieve the memory address of your variables,
-// then mess with them.
+// A pointer is a variable declared to store a memory address. Its declaration will
+// also tell you the type of data it points to. You can retrieve the memory address
+// of your variables, then mess with them.
int x = 0;
printf("%p\n", &x); // Use & to retrieve the address of a variable
// (%p formats a pointer)
// => Prints some address in memory;
+// Pointer types end with * in their declaration
+int* px; // px is a pointer to an int
+px = &x; // Stores the address of x in px
+printf("%p\n", px); // => Prints some address in memory
+
+// To retreive the value at the address a pointer is pointing to,
+// put * in front to de-reference it.
+printf("%d\n", *px); // => Prints 0, the value of x, which is what px is pointing to the address of
+
+// You can also change the value the pointer is pointing to.
+// We'll have to wrap the de-reference in parenthesis because
+// ++ has a higher precedence than *.
+(*px)++; // Increment the value px is pointing to by 1
+printf("%d\n", *px); // => Prints 1
+printf("%d\n", x); // => Prints 1
+
int x_array[20]; // Arrays are a good way to allocate a contiguous block of memory
int xx;
for(xx=0; xx<20; xx++){
x_array[xx] = 20 - xx;
} // Initialize x_array to 20, 19, 18,... 2, 1
-// Pointer types end with *
+// Declare a pointer of type int and initialize it to point to x_array
int* x_ptr = x_array;
-// This works because arrays are pointers to their first element.
+// This works because an array name is bound to the address of its first element
-// Put a * in front to de-reference a pointer and retrieve the value,
-// of the same type as the pointer, that the pointer is pointing at.
+// Arrays are pointers to their first element
printf("%d\n", *(x_ptr)); // => Prints 20
printf("%d\n", x_array[0]); // => Prints 20
diff --git a/clojure.html.markdown b/clojure.html.markdown
index 5086d2c2..24250a87 100644
--- a/clojure.html.markdown
+++ b/clojure.html.markdown
@@ -12,6 +12,9 @@ state as it comes up.
This combination allows it to handle concurrent processing very simply,
and often automatically.
+(You need a version of Clojure 1.2 or newer)
+
+
```clojure
; Comments start with semicolons.
diff --git a/python.html.markdown b/python.html.markdown
index 93fe5f25..4cfecbbd 100644
--- a/python.html.markdown
+++ b/python.html.markdown
@@ -8,6 +8,8 @@ Python was created by Guido Van Rossum in the early 90's. It is now one of the m
languages in existence. I fell in love with Python for it's syntactic clarity. It's basically
executable pseudocode.
+Feedback would be highly appreciated! You can reach me at [@louiedinh](http://twitter.com/louiedinh) or louiedinh [at] [google's email service]
+
Note: This article applies to Python 2.7 specifically, but should be applicable
to Python 2.x. Look for another tour of Python 3 soon!
@@ -134,9 +136,9 @@ except IndexError:
# (It's a closed/open range for you mathy types.)
li[1:3] #=> [2, 4]
# Omit the beginning
-li[:3] #=> [1, 2, 4]
-# Omit the end
li[2:] #=> [4, 3]
+# Omit the end
+li[:3] #=> [1, 2, 4]
# Remove arbitrary elements from a list with del
del li[2] # li is now [1, 2, 3]
@@ -167,7 +169,7 @@ tup + (4, 5, 6) #=> (1, 2, 3, 4, 5, 6)
tup[:2] #=> (1, 2)
2 in tup #=> True
-# However, you can unpack tuples into variables
+# You can unpack tuples into variables
a, b, c = (1, 2, 3) # a is now 1, b is now 2 and c is now 3
# Tuples are created by default if you leave out the parentheses
d, e, f = 4, 5, 6
@@ -407,3 +409,7 @@ j.get_species() #=> "H. neanderthalensis"
Human.grunt() #=> "*grunt*"
```
+## Further Reading
+
+Still up for more? Try [Learn Python The Hard Way](http://learnpythonthehardway.org/book/)
+