int [] array; // this is incorrect C++ syntax; valid Java/C#
The space for the array depends on where and how it is defined. If you declare
an array with the new operator you are placing the memory for your array on the
heap.
If you declare an array inside a function and not on the heap (i.e. int arr[ 25
] ) then this will be on the stack (most of the time this is true, the compiler
can move your array into the global data section in order to optimize the
function).
If you declare an array globally, or statically, then it will be placed in the
data section of the process's address space (along with your constants, etc).
Sometimes, you will see arrays defined with no size, like this:
int arr[] = { 0, 1, 2, 3 };
This means that the compiler will determine the size for you based on the
number of elements in it.
Hopefully, I didn't say anything incorrect to get the C++ ninja's jumping on
me. Either way, I hope this helps.
- Joe
--- On Tue, 1/27/09, Jos Timanta Tarigan <[email protected]> wrote:
From: Jos Timanta Tarigan <[email protected]>
Subject: [c-prog] total noob question about array
To: [email protected]
Date: Tuesday, January 27, 2009, 3:45 PM
Hi,
sorry for this noobish question :D
when you declare an array: int array[50], does the compiler allocate the
space(hence clean up the (unused)data, or it just create a pointer start and
end? how if you dont declare the space: int[] array; ?
how if for example i havent fill the array and try to call array[26]? will it
return an error or a 'false' value?
thanks :)
[Non-text portions of this message have been removed]