pointer arithmetic

This is a discussion on pointer arithmetic within the C Programming forums, part of the General Programming Boards category; how do i use pointer arithmetic for a mulit-dimension array? i know 1-D array is as follows: int array[3]; *(array) ...

  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, 04:45 AM
  2. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 03:29 PM
  3. Pointers, arithmetic, and order of operation.
    By Aerie in forum C Programming
    Replies: 4
    Last Post: 04-19-2005, 08:35 AM
  4. Replies: 41
    Last Post: 07-04-2004, 04:23 PM
  5. pointer arithmetic with characters
    By VanJay011379 in forum C++ Programming
    Replies: 6
    Last Post: 07-21-2002, 02:50 PM

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