Thread: Passing Array 2 Func...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    60

    Angry Passing Array 2 Func...

    I have forgotten how to pass an array to a function! I need to send an array to a function to perform a test on it's contents. Any help would be much appreciated!

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    You should pass it by reference

    Returntype FunctionName( ArrayElementtype* Name );

    Example

    int Array[4];

    void Search( int* Blah ); // you can also use []

    or, if you know that it has to be of a certain length, then do

    void Search( int (&Blah)[4] );

    You'd call either by just doing

    Search( Array );

    In the function's body, you'd access the array with the same syntax as if you were directly working with the array.

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    60
    you need to pass the array by reference using something like this
    function_name(&array_name[])

    im pretty sure this is right
    C++ can hurt.

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    60

    Reply to Polymorphic OOP

    Thanks a lot!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing a double array from main to another function
    By Loctan in forum C++ Programming
    Replies: 2
    Last Post: 01-04-2005, 05:19 PM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  3. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 01:01 AM
  4. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 12:09 PM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM