Question : Passing Array Arguments as Pointers

This is a discussion on Question : Passing Array Arguments as Pointers within the C Programming forums, part of the General Programming Boards category; "Pointers" in topic may be "Pointer's". Hi all. There is a two dimensional A[5][6] array declared and this is wanted ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    1

    Question Question : Passing Array Arguments as Pointers

    "Pointers" in topic may be "Pointer's".

    Hi all.

    There is a two dimensional A[5][6] array declared and this is wanted from me :

    . Pass the array A and its dimensions (number of rows and
    columns) to the FUNCTON1 as arguments.
    Number of rows and columns should be passed as POINTER
    arguments.
    And this is how i defined function and passed array into it :

    Code:
    void func1 (int *a1Ptr, int a1row, int a1column) // The function 
    
    func1 (*A, 5, 6); // This is how I pass array into it
    Program works and everything is ok.

    So my question is, did i do it right as it wanted ? If not, then how to do it like in the question.

    Thanks in advance.
    Last edited by NEMEAN; 12-04-2010 at 02:57 PM.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,528
    The question is actually unclear.

    But, presumably, the intent is that a1Ptr have a type that allows the notation a1Ptr[i][j] (within the function) to access the element A[i][j] (where A is the array passed by the caller). If that it the case, a1Ptr cannot be a just pointer to int, and A would not be passed as *A.

    If rows and columns should be passed as pointers, then a1row and a1column will need to be pointers, not ints.

    It's not quite clear what you mean by "Program works and everything is OK". The fact the code might compile does not mean it meets requirements.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy in reply to you, it is likely you deserve it. Suck it up, sunshine, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 11-21-2008, 04:27 PM
  2. Passing a 2d Array of pointers to a Function
    By miclus in forum C Programming
    Replies: 6
    Last Post: 09-11-2004, 08:34 AM
  3. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 08:48 PM
  4. passing structs & pointers to structs as arguments
    By Markallen85 in forum C Programming
    Replies: 6
    Last Post: 03-16-2004, 07:14 PM
  5. Question about Templates and passing arguments
    By supaben34 in forum C++ Programming
    Replies: 2
    Last Post: 10-13-2002, 02:32 AM

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