PREV INDEX NEXT

Author: Stan Eisenstat
Subject: Re: [Cs223] Length of Array
Date: Tuesday, 14 Apr 2020, 07:55:40


    > Message Posted By: Unknown
    >
    > I'm trying to find the length of an array using
    >
    > sizeof(array) / sizeof(array[0])
    >
    > but when I do it I get this warning
    >
    > Hash.c:76:32: warning: division `sizeof (struct triple *) / sizeof (struct
    > triple)' does not compute the number of array elements
    > [-Wsizeof-pointer-div]
    >    76 |   int lenArray = sizeof(array) / sizeof(array[0]);

You did not specify how array was declared, but judging
from the error message it must have been

  struct triple *array;

If so, then sizeof(array) is 8 = the size of a pointer
to a struct.  The warning is given since this result is
probably not what you were expecting.
=====

    > Is there a different way I can find the length of the array?

Keep it in a separate variable.

--Stan-
PREV INDEX NEXT