Getting arrays and structs into and out of functions,...

Ted L. Glenn tlglenn at cs.arizona.edu
Thu Apr 18 08:55:07 AEST 1991


In article <1991Apr17.212135.5922 at milton.u.washington.edu>, Rick Burgess writes
> I think I need to clarify my question.  I am, as yet, a novice so please
> realize I need the simple and the complex answers.  I wish to get structs
> and arrays into and out of my functions in ways which are appropriately
> clear, regular/normal/standard, efficient, and hopefully even orthoganal.


     C will pass the address of the first element of the array to the function,
which will be expecting an address. So, in general you can:

         call_f(array[10]) <-- I wonder if the 10 is really required here...
                                 but it works for me on Turbo C.

         void call_f(array[]) <--Notice no 10. The function is only expecting
the address of the beginning of the array. You can still do array[0]++ or
something, but be careful not to reference the array outside of it's
initially declared bounds (remember, an array of 10 goes from 0 to 9!).

-- 
        -Ted L. Glenn             "Don't worry, be happy!" <--Ack! Pffffhhht!
         tlglenn at cs.arizona.edu        tlglenn at hacks.arizona.edu
         G19382105 at ccit.arizona.edu    G19382105 at ARIZRVAX.BITNET



More information about the Comp.lang.c mailing list