Re: How to know the size of array




manochavishal@xxxxxxxxx wrote:
void foo(int * array)



void foo(int *array, size_t len)


{


Now the array size is in `len`.

Thanx for the quick reply.

I think i read somewhere that i can get the size by:

You could have read it in my reply as well, have you scrolled all the
way down. Do that now.

(sizeof(array) ) / (sizeof(element))

This is not the preferred syntax. See your textbook.

in this case it will be

(sizeof(array)) / (sizeof(int))

Look at my previous post, interspersed with your code.

I am not sure about this. Can we get the sizeof array to return the
size of all its elements.
Can sizeof find where the array is getting finished or it will just
give me the size of element.

Look at other replies in this thread.

Is there no way to get the size of array without passing the its
length.

Use the "sentinel" if you have a value that cannot happen otherwise. I
told you that already.

--
BR, Vladimir

.



Relevant Pages

  • Re: A couple of things from H&S
    ... expression of array type decays to a pointer to the array's first ... element *unless* it's in one of three contexts: the operand of sizeof, ... is quite obvious, p is the pointer. ...
    (comp.lang.c)
  • Re: Null terminated strings: bad or good?
    ... specified type, it must not be possible to use callocto allocate such ... allocate such an array, that still doesn't make it possible for ... For any object that you can actually define in your program, with either static or automatic storage duration, "sizeof object" is supposed to give the size of that object; the standard provide no exceptions to this requirement. ...
    (comp.lang.c)
  • Re: C Strings
    ... sizeof ... More generally, given any array object, we can find a pointer to ... works quite as well for C99 as it did for C89, ...
    (comp.lang.c)
  • Wording glitch: sizeof array vs. sizeof (array)
    ... A parenthesized expression is a primary expression. ... Except when it is the operand of the sizeof operator or the unary ... & operator, or is a string literal used to initialize an array, an ...
    (comp.std.c)
  • Re: Question about sizeof
    ... Mark double $$ ... This is true in any situation, not only with sizeof ... Cant you keep original values in the array instead of the variable names? ... -Each type of discography is associated with an array that contains ...
    (comp.lang.php)