Thread: Arrays and pointers, confused.

  1. #1
    Registered User
    Join Date
    Sep 2014
    Posts
    83

    Arrays and pointers, confused.

    Hi,

    In my book about C I read that arrays (for example int array[100]) are really pointers. What confuses me then is that you cannot write:

    int array1[100];
    int array[100]
    array1 = array2; // wrong

    Shouldnt you be able to assign a pointer to a pointer?

    You can write:
    int *ptr;
    ptr =array2;

    Why isnt this the same as the above assignment? In both cases a pointer is assigned to another pointer (considering an array is a pointer).

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    In my book about C I read that arrays (for example int array[100]) are really pointers.
    Your book is wrong. In many expressions an array is treated as a pointer, but an array is not a pointer itself. You've found one place where there's an obvious difference.

  3. #3
    Registered User
    Join Date
    Sep 2014
    Posts
    83
    OK thanks. I was beginning to think an array is the same thing as a pointer.

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513

  5. #5
    Registered User
    Join Date
    Sep 2014
    Posts
    83
    Good links ty.

  6. #6
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    You're welcome. There's a lot of good info on there, I'd recommend browsing through it if you get some time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Confused about Pointers
    By JoshD75 in forum C Programming
    Replies: 7
    Last Post: 03-28-2011, 09:43 PM
  2. Still confused with pointers
    By desmond5 in forum C Programming
    Replies: 8
    Last Post: 02-23-2008, 09:32 PM
  3. confused with pointers
    By Mahdi123 in forum C Programming
    Replies: 2
    Last Post: 04-25-2007, 01:08 PM
  4. i'm getting confused w/ arrays
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 02-20-2002, 08:25 AM
  5. Very confused with pointers
    By killerasp in forum C++ Programming
    Replies: 5
    Last Post: 01-30-2002, 06:44 PM