sizeof C Keyword sizeof
Return size of a data element
sizeof is a C operator that returns a constant int that gives the
size of any given data element. The element examined can be a
data object, a portion of a data object, or a type cast. sizeof
returns the size of the element in chars; for example
long foo;
sizeof foo;
returns four, because a long is as long as four chars.
sizeof can also tell you the size of an array. This is
especially helpful for use with external arrays, whose size can
be set when they are initialized. For example:
char *arrayname[] = {
"COHERENT", "Mark Williams C for the Atari ST",
"Let's C", "Fast Forward"
};
main()
{
printf("\"arrayname\" has %d entries\n",
sizeof(arrayname)/sizeof char*);
}
sizeof is especially useful in malloc routines, and when you need
to specify byte counts to I/O routines. Using it to set the size
of data types instead of using a predetermined value will in-
crease the portability of your code.
***** See Also *****
C keywords, data types, operators
COHERENT Lexicon Page 1