Please review this guide for clarity, accuracy, etc. so I can
hopefully compile a very good tutorial on how to use pointers in C,
including advanced topics, that is easy to follow and exposes the
details.
http://thelinuxlink.net/~fingolfin/pointer-guide/
Your use of "lvalue" and "rvalue" is slightly non-standard, but
IMO consistent enough. The usual terminology would have it
that an /expression/ /is/ an lvalue or an rvalue, depending on
whether the expression denotes an object with an /address/.
You use "lvalue" to mean /address/, and "rvalue" to mean
/value/. Consistent enough, but irking to pedants.
The HTMLification of the first sample program, the one that
begins '/* vim:ts=4 */', is absolutely unreadable on a white
background (the default in most GUI web browsers). Do not
use light green or cyan text on a white background. Prefer
no coloration, especially since you can't seem to decide on
a consistent scheme: why is 'fprintf' black but 'stdout'
magenta, for example?
HTML could be used to great advantage in the body text of
the tutorial, however. Consider bolding new terms on their
first appearance, to make it easier to skim the large
paragraphs; and I recommend using <tt></tt> or <i></i>
around code snippets in the text such as 'foo' and 'frob'.
The line '/* vim:ts=4 */' is completely unnecessary to
your tutorial, BTW, and will only confuse non-Unix types.
Suggest removing the hard tabs from your HTML source code
as well, since I doubt many browsers can effectively deal
with them. Suggest the use of <pre> to format source code.
Suggest 'return 0;' from 'main'. This is not required
by C99, but is a good practice in both C90 and C99. And
you are supposedly writing to instill good practices in
newbies...
"Therefore, the return type of *bar is int..." Delete
the word "return" from this sentence; operators /yield/
values. Functions /return/. Unary * is not a function,
and thus /returns/ nothing.
"The relevance of them will be revealed yet..." Insert
"not" before "be," of course.
s/interchangably/interchangeably/
"And since char's are one byte in length (at least on
all systems I know)..." 'sizeof(char)' is 1 (byte) by
definition. Whether any particular "system" has a
machine-level concept of "byte" is not relevant to C
programming. But then neither is using actual numbers
to refer to "addresses in RAM," so you'll just have to
pick a wording that will satisfy the pedants. Suggest
simply removing the parenthetical comment.
"...in short it is a data type that is made to
reference other data through its lvalue." Confusing.
Firstly, 'short' is a data type, so you've just majorly
confused the skimmers, who aren't paying much attention
to your grammatical flourishes. Secondly, either your
grammar or your content is wrong in the second half of
that sentence; a pointer is an object which references
other data through its "rvalue" (its /value/), or
equivalently a pointer /contains/ another datum's "lvalue"
(its /address/).
"The data an array accesses cannot be changed.
Therefore they are not pointers." Grammar strikes again!
First, the data accessed by an array *can* be changed;
consider 'arr[0] = 42; arr[0] = 43;'. Secondly, the
data accessed by an array *can* be pointers; consider
'int *arp[10];'. You mean, "An array cannot be changed
to 'point' to other data; therefore arrays are not pointers."
s/syntax sugar/syntactic sugar/
Your HTMLification is screwed up majorly in "Basic
Pointer Arithmetic," where it actually "eats" the 'for'
keyword in your loop. Yet another reason to drop the
colorization.
"When you add a number to a number type, such as an int
or double, you get straight addition. But when you do it on
pointers, the number is automatically multiplied by the size
(in bytes) of the type to which the pointer points." This
is how it's usually explained, true. But your lead-in is
somewhat silly, since you never say what you mean by "straight
addition." Obviously the machine code for adding 1 to a
pointer is different from that for adding 1 to an 'int';
but the machine code for adding 1 to a 'double' is often
*far* more complicated. Yet you call the latter two "straight"
addition! IMO it would make more sense simply to tell the
reader that addition on pointers is /defined/ the way it
is, and let them determine for themselves whether it's
weird or not.
s/deference/dereference/
"...the arithmetic operators take precedence over pointer
[dereference] anyway..." This is just flat-out /wrong/.
Remove it, and the surrounding misdirection.
Finally, although the tutorial is obviously not yet
completed, I must urge you to add material on the []
indirection operator. The reader is currently left thinking
that '*(kochba+i)' is the only way to dereference a pointer.
[On a lighter note, I must say I've never seen 'kochba' used
as the third element of 'foo, bar,...'! Very... quirky.]
HTH,
-Arthur