pointer arrays

This is a discussion on pointer arrays within the C Programming forums, part of the General Programming Boards category; i hav e a few questions about pointers: 1) int array[100]; int *ch; ch=array; is it true?if it is true ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    80

    Post pointer arrays

    i hav e a few questions about pointers:
    1)
    int array[100];
    int *ch;
    ch=array;
    is it true?if it is true why we use pointer becouse it can be likle that int array[100];
    ....
    ....
    array[i];

    is this for dynamic memory

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    There is no need for a pointer in your simple example. Dynamic arrays in the way you mentioned is not possible (perhaps on some compilers), so you need to use pointers and dynamic allocation instead:

    int* MyArray;
    MyArray=(int*)malloc(i); //Syntax?
    ...
    free(MyArray);
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,340
    >int array[100];
    >int *ch;
    >ch=array;
    This is valid, but doesn't get you any more than 100 ints
    ch[i] accesses the same memory as array[i]
    Just a slightly different way of going about it

    If you want to choose the size at run time, then
    int size = 100;
    int *ch = malloc( size * sizeof(int) );

  4. #4
    Registered User Led Zeppelin's Avatar
    Join Date
    Mar 2002
    Posts
    17

    Search the message board

    You may want to do a search of dynamic arrays on c board, because just last week I recieved help on this same topic from Prelude. If you cant find it let me know and I can find it and link it for you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Replies: 5
    Last Post: 04-04-2009, 03:45 AM
  3. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  4. pointer arrays!!!
    By condorx in forum C Programming
    Replies: 1
    Last Post: 05-14-2002, 08:55 AM
  5. Replies: 4
    Last Post: 11-05-2001, 01:35 PM

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