Lies in education [was Re: The "loop and a half"]

Gregory Ewing greg.ewing at canterbury.ac.nz
Fri Oct 13 00:50:45 EDT 2017


Stefan Ram wrote:
> void
> i_know_i_was_passed_a_pointer_to_an_array_and_how_many_elements_are_in_it
> ( char( *a )[ 4 ] )
> { for( int i = 0; i < 4; ++i )
>   putchar( ( *a )[ i ]); }

Only because you've statically made the array size part of
the type. Your original example didn't do that; presumably
it was intended to accept arrays of any size and cope
with them dynamically.

That's usually what you want, and the way you do that in
C is to pass a pointer to the first element and convey
the size separately. So the kind of declaration you
used above is hardly ever seen in idiomatic C code.
(I've *never* seen it done in real life.)

-- 
Greg



More information about the Python-list mailing list