Thread: pointer arithmetic

  1. #1
    Unregistered
    Guest

    Question pointer arithmetic

    how do i use pointer arithmetic for a mulit-dimension array?
    i know 1-D array is as follows:

    int array[3];

    *(array) == array[0]
    *(array + 1) == array[1]
    *(array + 2) == array[2]

    for multi-d array:

    int array[3][3];
    ? == array[0][0]
    ? == array[0][1]
    ? == array[0][2]
    ? == array[1][0]
    etc........

    thank you.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    I may be wrong with the parenthesis placement, but here's what I think...

    *(*array) == array[0][0]
    *(*array + 1) == array[0][1]
    *(*array + 2) == array[0][2]
    *(*array + 3) == array[1][0]
    *(*array + 4) == array[1][1]
    etc...

  3. #3
    Registered User *pointer's Avatar
    Join Date
    Oct 2001
    Posts
    74
    *( *array ) == array[0][0]
    *( *( array + 0 ) + 1 ) == array[0][1]
    *( *( array + 0 ) + 2 ) == array[0][2]
    *( *( array + 1 ) + 0 ) == array[1][0]
    *( *( array + 1 ) + 1 ) == array[1][1]

    Pointer arithmetic is just like using subscripts just a bit harder to read.
    pointer = NULL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 04-04-2009, 03:45 AM
  2. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  3. Pointers, arithmetic, and order of operation.
    By Aerie in forum C Programming
    Replies: 4
    Last Post: 04-19-2005, 07:35 AM
  4. Replies: 41
    Last Post: 07-04-2004, 03:23 PM