Thread: Pointer to two dimentional array

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    47

    Pointer to two dimentional array

    Hi ,how can I do that
    Code:
    double *px;
     px=a;
    when I do that is giving me -warning assignment from incompatible pointer type in c
    a is two dimetional array of doubles
    Last edited by lio; 11-06-2010 at 10:29 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Code:
    double a[10][20];
    double (*pa)[20] = a;  // a pointer to an array of 20 doubles
    Note that this is different from say
    Code:
    double **pa; // pointer to pointer to double
    double *pa[20]; // an array of 20 pointers to double
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by lio View Post
    Hi ,how can I do that
    Code:
    double *px;
     px=a;
    when I do that is giving me -warning assignment from incompatible pointer type in c
    a is two dimetional array of doubles
    Code:
    // first assign px to actually point to something
    double pv;
    double *px = &pv;
    // then provide array coordinates
    *px = a[x][y];
    You can't assign an array to a single value.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 05-29-2009, 05:48 AM
  2. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  3. sorting the matrix question..
    By transgalactic2 in forum C Programming
    Replies: 47
    Last Post: 12-22-2008, 03:17 PM
  4. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  5. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM