Thread: Array question

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    81

    Array question

    I have a question that may help me with my code. When we use reference the name of the array (without any indexing), what does this really mean?

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    &array[0]
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    81
    So basically does this means that it's calling the address of the array starting at subscript 0?

    Would it take on the value of the whole array if it were to be passed into a function?
    "Our greatest glory consists not in never failing,
    but in rising every time we fall."

    Oliver Goldsmith (1730-1774).
    Anglo-Irish writer, poet and playwright.

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    An array argument is a pointer to the first element of the array, not the entire array.

    Makes sense if you think about it. An array doesn't have a "value", per se, and even if it did, you sure wouldn't want to 'copy' an array of 100,000 bytes in order to pass it to a function 'by value'.

    "Passing by reference"? Well, the problem is that a reference is a constant value which means that it can't be incremented/decremented the way pointers can. (Note the segue here. )

    By passing a pointer to the array (first element), we've got the functionality that we're looking for without a ton of overhead.

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    81
    Thanks Skipper.... actually made sense!! Appreciate it!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic Mutli dimensional Array question.
    By fatdunky in forum C Programming
    Replies: 6
    Last Post: 02-22-2006, 07:07 PM
  2. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. array question?
    By correlcj in forum C++ Programming
    Replies: 1
    Last Post: 11-08-2002, 06:27 PM