[Courses] [C] Beginner's Lesson 4A: Arrays, Qualifiers, and Reading Numbers

Laurel Fan laurel at sdf.lonestar.org
Fri Oct 11 10:05:07 EST 2002


On Fri, Oct 11, 2002 at 05:23:40PM +0300, Anca M. Holban wrote:
>      fload data[5]={34.0,27.0,45.0,82.0,22.0};

Incidentally, you can do:
	float data[] = {34.0, 27.0, 45.0, 82.0, 22.0};

and the compiler can figure out that it needs to allocate space for 5
floats.   To get back the size of the array if you need it, you can use

	sizeof(data)/sizeof(float);

as mentioned before, or alternatively,

	sizeof(data)/sizeof(data[0]);

This way, you can add an element to the array, or even change its
type, and only have to change things in one place.
	
-- 
laurel at sdf.lonestar.org
http://dreadnought.gorgorg.org



More information about the Courses mailing list