how has C bitten you?

Andrew Koenig ark at alice.UUCP
Thu Aug 1 01:33:01 AEST 1985


> Andrew:
>      Regarding

>	int i,a[10];
>	for(i=0; i<=10; i++)
>		a[i] = 0;

> you should have expected some problems, as you are writing one past the end of
> the array! The correct test to use is < not <=!

Yes, I know that!

The point is that this is an example of something that looks reasonable
at first glance and isn't, because of a property that C does not
share with many other languages (in most languages, a 10-element
array has an element #10).

Read my article again.  I am looking for examples for my collection,
not asking for advice on how to solve this particular problem.



More information about the Comp.lang.c mailing list