Thread: Array Help

  1. #1
    Coconut
    Guest

    Question Array Help

    Can anyone explain and give an example of how to use and manipulate the pointer array as following:

    int (*arrPtr)[10];

    Does int (*arrPtr)[10] represent for one dimentional array or 2 Dim?
    How to pass it into a function?
    I haven't seen this type of array definition oftenly? Why people
    try to avoid to use it?
    Your help would be appreciated.
    Regards,

    Coconut

  2. #2
    That one kid
    Guest
    int (*arrPtr)[10];
    This is used to delcare a pointer to an array of 10 integers. You have to put the parenthesis around the name of the pointer in order to tell the compiler that you are wanting ONE pointer to an array of TEN integers and not TEN pointers to TEN different integers which would be the case if you left out the parenthesis.
    Maybe someone can help clarify what I am trying to say.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Here's a reference site often quoted round here....
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I honestly don't see the point in bothering with the cumbersome "(*ptr)[10]" aspect. Why bother when this will suffice?

    Code:
    int *ptr;
    int array[10];
    
    ptr = array;
    Let's face it, it's not like your compiler is going to prevent you from accessing "ptr[11]" in either example. So really, what's the point?

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Coconut
    Guest
    Originally posted by That one kid
    int (*arrPtr)[10];
    This is used to delcare a pointer to an array of 10 integers. You have to put the parenthesis around the name of the pointer in order to tell the compiler that you are wanting ONE pointer to an array of TEN integers and not TEN pointers to TEN different integers which would be the case if you left out the parenthesis.
    Maybe someone can help clarify what I am trying to say.
    Thanx for pointing out of this.
    But can anyone show a example of the use of
    int *P[10];
    Does it pass into in function as the same as
    int (*arrPtr)[10]. I guess it also a 2Dim array.
    Can i make an assignment like: P = arrPtr; ?
    Again, thanks everybody who provide help.
    Coconut

  6. #6

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM