On Tue, 06 Mar 2007 16:03:20 +0530, At_sea_with_C wrote:
Hello,
I'm considering reading some C tutorials. I found this one.
http://www.crasseux.com/books/ctutorial/
(The GNU C Programming Tutorial)
Can anyone tell me if it is good or not? Also do you have any other
recommendations for other good tutorials?
Thanks a lot.
I had a brief look at one section "Advanced operators" and found some
mistakes (typos maybe but confusing none the less).
In the subsection on the comma operator: "You can separate almost any
kind of C statment from another with a comma operator. The comma-separated
expressions are evaluated from left to right and the value...".
But the comma operator separates expressions, not statements.
In the subsection "Hidden operators and values"
"The value of an expression is the result of the operation carried out in
the expression. Increment and decrement statements have a value that is
one greater than or one less than the value of the variable they act upon,
respectively.
Consider the following two statements:
c = 5;
c++;
The expression c++ in the above context has the value 6.
"
No, it has the value 5, and after the above c has the value 6.
The value of an expression is *not* always the result of the operation.
And note the confusion in "Increment and decrement statements".
In the subsection "Postfix and prefix ++ and --"
"int my_int = 3;
printf ("%d\n", my_int++);
The increment operator is hidden in the parameter list of the printf call.
The variable my_int has a value before the ++ operator acts on it (3) and
afterwards (4).
Which value is passed to printf? Is my_int incremented before or after
the printf call? This is where the two forms of the operator (postfix and
prefix) come into play.
If the increment or decrement operator is used as a prefix, the operation is
performed before the function call. If the operator is used as a postfix, the
operation is performed after the function call."
I don't think the talk of before/after function call is helpful.
If my_int were a global variable then assuming the increment in
f(my_int++) happened after the call to f() would lead to errors!
I suppose 3 errors (I didn't notice any others) in a section is not too
bad, but I don't think I'd recommend the tutorial.
Duncan