Thread: Passing an array to a function as a parameter

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    44

    Passing an array to a function as a parameter

    Hi,

    When you give an array as a parameter to a function, are you working with a copy or with the address to the array? I was pretty sure you were just working with the address but I am a bit confused because I saw prototypes where the parameter wasn't just the array name but for example:
    function(int a[rows][columns])

    I am aware of the fact you have to include the columns when you are passing a 2D array.

    Regards,

    boxden

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    you are passing the pointer to the first element, but compiler needs to know the type of the pointer, which is in case of 2D arrays is pointer to 1D array of N ints( or doubles or whatsoever), so you need to include the N...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Replies: 42
    Last Post: 12-19-2004, 08:59 AM