Richard Heathfield said:
Enteng said:
Yes, absolutely. Pascal is possibly a better starting choice (because it was
actually designed as a teaching language, and was designed well), but C is
a fine choice too.
[...]
If you choose C as your first language, be prepared for the fact that
it won't necessarily detect your errors for you. The C language, and
C implementations, tend to assume that you know what you're doing. If
you write a program tries to drive over a cliff, don't expect any
guardrails to prevent you from doing so, or airbags to cushion your
landing. C gives you the parts and tools to build your own
guardrails, but it doesn't require you to do so, and it doesn't
guarantee that your self-built guardrails will actually do their job.
A simple example:
char s[5];
strcpy(s, "Hello, world");
The first line declares an array of 5 characters. The second attempts
to copy the string "Hello, world" into that array. In some languages,
the equivalent of this code will fail cleanly, perhaps by printing an
error message and terminating your program. In C, however, it's very
likely to go ahead and copy the entire string to the location you
specified, clobbering adjacent memory with unpredictable results. The
technical term for this is "undefined behavior".
There are add-on tools to address this kind of thing.
Remember that it's not particularly difficult to write incorrect code
in *any* language. But C, by itself, expends less effort than some
other languages to catch your errors for you.
But if you can learn to write reasonably robust programs in C, your
experience should carry over to other languages.