Thread: Calling multiple arrays to the same function

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    26

    Calling multiple arrays to the same function

    So I'm just having trouble with what c can actually do and how.
    I've got a program which calls a function at some points to evaluate multiplication of values within different arrays. I have 3 arrays, and at different points in my program I want to calculate the same set of multiplications with each using only one external function. Inside the function, I know what I'm doing but I'm not sure of the syntax for telling a function to take the sent array (i assume using pointers!). Could anyone point me to a tutorial or a brief explanation?
    Cheers.

  2. #2
    Registered User
    Join Date
    Nov 2010
    Posts
    6
    calling function:
    result = multiply(array1, array2, array3);

    e.g. int multiply(array1[size], array2[size], array3[size])
    {
    return someInt;
    }
    Last edited by wejnc; 11-21-2010 at 12:31 PM.

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    You'll want to give those arrays types:
    Code:
    int multiply(int array1[], int array2[], int array3[])
    {
    }
    You can give a size to the arrays or not; it is not used.

    And you're right about using pointers, because confusingly, the above notation means that the three parameters are pointers, not arrays. You don't have to do anything special to pass the array, though; it will get converted to a pointer automatically if you just use its name, as shown by wejnc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM