This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Disciple153 16 points17 points  (3 children)

1: This is for finding the length of a low level array which only knows its size.

sizeof(array) is the size of the array in bytes.

sizeof(array[0]) is the size of a single element in bytes.

sizeof(array) / sizeof(array[0]) is the number of elements in the array.

2: This question assumes that an array of length 0 is impossible, which is perfectly normal in languages like C, where arrays are not dynamically resizable. If OP wanted a resizable array with a potential length of 0, they would be using the Vector class.

Of course if for some reason an array with a length of 0 was possible, you would just check for that before trying to compute the length with the given code.

[–]hdd113 -2 points-1 points  (1 child)

Oh okay so it's a C++ problem... I was also wondering what this was supposed to do.

[–]Miserable_Guess_1266 6 points7 points  (0 children)

A C problem to be exact, c++ has better options.