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

This is a discussion on how do i pass an array to a function??????? and pass the array back after it gets sor within the C Programming forums, part of the General Programming Boards category; i dont know how to pass an array to a function so it can be sorted and passed back to ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    22

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

    i dont know how to pass an array to a function so it can be sorted and passed back to be displayed!!!!!
    i know how to do the sort just not how to pass the array

  2. #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.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    17
    to pass the array.
    put
    void array_name(int []) if it is an integer array

    then when you are calling your function
    put

    function_name(array_name)


    you do not need to return the array from the function because any change you make to the array will be changed in main().

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    22
    greast thanx

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, 05:23 AM
  2. Replies: 1
    Last Post: 10-21-2007, 08: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, 06:06 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 10:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21