Just need some help understanding the sizeof() operator.
In main() I have an array
int list[] = {1,2,3,4,5,6,7,8,9,0};
if still in main() I use a sizeof() operator: sizeof(list)
it'll return and size of this array. It'll be 40. (10 ints)
But when I pass this array to some function from main(list):
int getSize( int * list){
int size = (sizeof(list)/sizeof(int));
}
it'll return 1 (which is size of the pointer "list" itself).
and as you may guess I don't want that.....
Can anyone tell me if it's possible to get the size of
an array that pointer to it has been passed to the function?
(the function getSize(int * list) just like in above code?)
Thanks
Gregg
Thanks Grey Wolf but I knew this. I'm just wondering if it IS possible to get the size of an array pointed by
a pointer that I just passed to the function. I guess what I'm trying to understand here is that is the sizeof
operator working with objects located on the call stack. (where parameters are stored along with local variables, return address etc.) and if there is how?
Thanks
Thanks Gray,
This works when inside the main. If I call the function (and pass pointer on the call stack to that array)
and then call the macro I have the same problem.
I guess this doesn't with functions...
Thanks