Re: Newbie-Question: Function-Parameters

From: dandelion (someone_at_meadow.net)
Date: 10/07/04


Date: Thu, 7 Oct 2004 17:00:15 +0200


"merman" <merman@snafu.de> wrote in message
news:416556a4$0$168$9b622d9e@news.freenet.de...
> Hi,
>
> What is the most common way to pass an array into a function - and how
> can I return it?

By pointer, which is even simpler than you may think. you could call

void foobar(int bla[])
{

}

or

void foobar( int* bla)
{

}

using

int barfoo[3] = { 1, 2, 3 };
foobar(barfoo);

The two forms of function foobar are (more or less) equivalent. the sole
identifier 'barfoo' (as opposed to barfoo[2]) evaluates to a pointer to the
array.

See? Easy.



Relevant Pages

  • Re: Newbie-Question: Function-Parameters
    ... > By pointer, which is even simpler than you may think. ... Don't forget to pass the length of the array to the function.. ... void foobar(int bla[], size_t len) ...
    (comp.lang.c)
  • Re: char **argv & char *argv[]
    ... "pointer to pointer to char". ... >> pointer)) pointing to the first element of an array. ... so we have to start adding more context. ... type "pointer to char", rather than "array MISSING_SIZE of char". ...
    (comp.lang.c)
  • Re: why cannot assign to function call
    ... hypothetical C-like languages, ... sizeof business would still indicate that a pointer was being passed. ... talk about variables of an array type. ... the earlier version of the standard didn't have numbered ...
    (comp.lang.python)
  • Re: multi dimensional arrays as one dimension array
    ... please - where does the standard say that such a conversion ... Pointer conversion yields a pointer to the same object as ... exist only where there are array declarations. ...
    (comp.lang.c)
  • Re: Pointer Equality for Different Array Objects
    ... Pointers to the same object are pointers to the same region of data storage. ... A pointer comaprison (for exact equality, ... we have the vague ("if the array is large enough"). ...
    (comp.lang.c)