Thread: how do i pass an array to a function??????? and pass the array back after it gets sor

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Registered User dharh's Avatar
    Join Date
    Jan 2002
    Posts
    51
    prototype/function would look something like this:

    void function(int array2[], int size);

    the call would look something like this:

    #define ROWS 50

    int array[ROWS];

    function(array, ROWS);

    Basicaly whatever gets done with array2 gets done with array. Your really passing the address of the original array. Theres really no way to pass the "contents" of the whole array at one, unless you only want to pass one element.

    You dont necessarility need to pass the size, but I like to make as generic functions as I can that will work with any array rather than having to hard code the size of the array in the function. Unless your dealing with char arrays in which case you'll most likely be dealing with one that ends in '\0'.
    Last edited by dharh; 04-02-2002 at 01:04 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Replies: 1
    Last Post: 10-21-2007, 07:44 AM
  3. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM