Thread: pointers

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #12
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    Quote Originally Posted by std10093 View Post
    To me it is clearer without brackets.
    If you have a three dimensional array declared as `double A[x][y][z]' is it clearer to address an arbitrary element with indices a, b, c as

    A[a][b][c] = foo;

    or

    *(((A+a*x*y)+b*x)+c) = foo;

    ? Especially when there are more than two dimensions, the bottom form becomes tedious and error prone.

    Creating a function that operates on the array A will always require 4 parameters no matter if you use the pointer notation or the array notation: you need to pass one parameter representing the array A, and you need to pass three integer parameters representing the maximum bound of each dimension.

    In other words, your choices for a function bar are pretty much just these two:

    void bar1(int x, int y, int z, double *A);

    void bar2(int x, int y, int z, double A[x][y][z]);
    Last edited by c99tutorial; 01-14-2013 at 05:24 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. size of struct with pointers and function pointers
    By sdsjohnny in forum C Programming
    Replies: 3
    Last Post: 07-02-2010, 05:19 AM
  2. Storing function pointers in generic pointers
    By Boxknife in forum C Programming
    Replies: 6
    Last Post: 08-01-2009, 01:33 PM
  3. Pointers to objects -- passing and returning pointers
    By 1veedo in forum C++ Programming
    Replies: 4
    Last Post: 04-04-2008, 11:42 AM
  4. Problem with malloc and pointers to pointers
    By mike_g in forum C Programming
    Replies: 7
    Last Post: 03-29-2008, 06:03 PM
  5. weak pointers and use_count smart pointers
    By Mario F. in forum C++ Programming
    Replies: 2
    Last Post: 07-29-2006, 07:54 AM