diff options
author | Sergey Avseyev <sergey.avseyev@gmail.com> | 2013-08-14 23:15:17 +0300 |
---|---|---|
committer | Sergey Avseyev <sergey.avseyev@gmail.com> | 2013-08-14 23:18:10 +0300 |
commit | 162b5bb60dea93dac591005a73956be663313761 (patch) | |
tree | 7004d9ddd2834b950ea8f234bc13a64d742ed8d0 | |
parent | 991e7b0045615427f5ccb12c3c85f262a2ac54e8 (diff) |
Fix typo about how pointers are declared
Of course it is completely valid that star can go right after type
name, but it might be not that obvious that during declaration the
star is associated to the variable, not with the type name.
-rw-r--r-- | c.html.markdown | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/c.html.markdown b/c.html.markdown index d243b19d..2b50efa0 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -230,10 +230,13 @@ 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 + +// Pointers start with * in their declaration +int *px, not_a_pointer; // 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 +printf("%d, %d\n", (int)sizeof(px), (int)sizeof(not_a_pointer)); +// => Prints "8, 4" on 64-bit system // To retreive the value at the address a pointer is pointing to, // put * in front to de-reference it. |