Passing an array to a function as a parameter

This is a discussion on Passing an array to a function as a parameter within the C Programming forums, part of the General Programming Boards category; Hi, When you give an array as a parameter to a function, are you working with a copy or with ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    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...
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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, 03: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-30-2005, 12:21 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM
  5. Replies: 42
    Last Post: 12-19-2004, 08:59 AM

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