Pointers

This is a discussion on Pointers within the C Programming forums, part of the General Programming Boards category; I have one question if I have *X[2] (*X)[2] what do those mean? Also, what would a poosible decleration of ...

  1. #1
    Microsoft. Who? MethodMan's Avatar
    Join Date
    Mar 2002
    Posts
    1,198

    Pointers

    I have one question
    if I have *X[2]
    (*X)[2]
    what do those mean?
    Also, what would a poosible decleration of X be?

    Thanks a lot, Im new to C, and am not familiar with pointers

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    #include <stdio.h>
    int main(void)
    {
        int a,b,c,*x[3] = { &a, &b, &c };
    
        a = 10;
        b = 20;
        c = 30;
    
        return printf( "%d vs %d\n", *x[2], (*x)[2] );
    }
    The first gives you the value contained in the array, the second dereferences the pointer first and as an end result you get the address of the second pointer rather than its contents.

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

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    Code:
    #include <stdio.h>
    
    int main ( void ) {
        int a = 1, b = 2, c = 3;    // 3 ints
        int d[3] = { 10, 11, 12 };  // an array of 3 ints
        int *x[3] = { &a, &b, &c }; // 3 pointers to 3 ints
        int (*y)[3] = &d;           // one pointer to an array of 3 ints
    
        printf( "%d %d %d\n", a, b, c );
        printf( "%d %d %d\n", d[0], d[1], d[2] );
        printf( "%d %d %d\n", *x[0], *x[1], *x[2] );
        printf( "%d %d %d\n", (*y)[0], (*y)[1], (*y)[2] );
        return 0;
    }
    And also read this
    http://pw2.netcom.com/~tjensen/ptr/cpoint.htm

  4. #4
    Microsoft. Who? MethodMan's Avatar
    Join Date
    Mar 2002
    Posts
    1,198
    Thanks a lot for the help!!!!!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MergeSort with array of pointers
    By lionheart in forum C Programming
    Replies: 18
    Last Post: 08-01-2008, 10:23 AM
  2. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 12:18 PM

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