.TH sizeof "" "" "C Keyword"
.PC "Return size of a data element"
.PP
.B sizeof
is a C operator that returns a constant
.B 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.
.B sizeof
returns the size of the element in
.BR char s;
for example
.DM
	long foo;
	sizeof foo;
.DE
.PP
returns four, because a \fBlong\fR is as long as four \fBchar\fRs.
.PP
.B 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:
.DM
char *arrayname[] = {
	"COHERENT",
	"COHware volume I",
	"COHERENT Device Driver Kit",
        "GNU C/C++"
};
.DE
.DM
main()
{
	printf("\e"arrayname\e" has %d entries\en",
		sizeof(arrayname)/sizeof char*);
}
.DE
.PP
.B sizeof
is especially useful in
.B 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 increase the portability of your code.
.SH "See Also"
.Xr "C keywords," c_keyword
.Xr "data types," data_type
.Xr "operators" operators
.br
\*(AS, \(sc6.3.3.4
