prev up next   top/contents search

comp.lang.c FAQ list · Question 6.23

Q: I want to know how many elements are in an array, but sizeof yields the size in bytes.

A: Simply divide the size of the entire array by the size of one element:

	int array[] = {1, 2, 3};
	int narray = sizeof(array) / sizeof(array[0]);

References: ISO Sec.

prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North