[LC++]Size of structure pointer/array

Paul Carter carterp at acm.org
Thu Aug 30 11:49:19 UTC 2001


All arrays are passed as pointers. "is" by itself evaluates to a pointer
to the first element of the array. So when the function is called, the
address of the first element is assigned to the "i" parameter.

sizeof(is) = 9*3 = 27, since "is" is an array
however the sizeof(i) = 4, since it is just a pointer

(assuming int is 32-bits)

-- 
Paul Carter [carterp at acm.org] [http://www.drpaulcarter.com/]

On Wed, Aug 29, 2001 at 09:29:11PM -0400, Paul M Foster wrote:
> Assuming:
> 
> //////////////////////
> 
> struct int_struct {
> 	int a;
> 	int b;
> 	int c;
> };
> 
> void is_func(int_struct *i); // defined elsewhere
> 
> int_struct is[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
> 
> is_func(is);
> 	
> ////////////////////
> 
> When I pass "is" to the is_func() function, am I passing the whole array
> of structures, just a pointer to the first element, or what? The size of
> "is", when passed to the function (and measured inside the function) is
> the size of a pointer. But I'm concerned that I've passed more than that
> on the stack.
> 
> Paul
> 
> _______________________________________________
> This is the Linux C++ Programming List
> : http://lists.linux.org.au/listinfo/tuxcpprogramming List



More information about the tuxCPProgramming mailing list