<s>
sizeof	B-Language
is	O
a	O
unary	O
operator	O
in	O
the	O
programming	O
languages	O
C	B-Language
and	O
C++	B-Language
.	O
</s>
<s>
Consequently	O
,	O
the	O
construct	O
sizeof	B-Language
(	O
char	O
)	O
is	O
guaranteed	O
to	O
be	O
1	O
.	O
</s>
<s>
The	O
actual	O
number	O
of	O
bits	O
of	O
type	O
char	O
is	O
specified	O
by	O
the	O
preprocessor	B-Application
macro	I-Application
,	O
defined	O
in	O
the	O
standard	O
include	B-Language
file	I-Language
limits.h.	O
</s>
<s>
The	O
result	O
of	O
sizeof	B-Language
has	O
an	O
unsigned	B-Algorithm
integer	O
type	O
that	O
is	O
usually	O
denoted	O
by	O
size_t	O
.	O
</s>
<s>
Data	O
types	O
may	O
not	O
only	O
be	O
primitive	O
types	O
,	O
such	O
as	O
integer	O
and	O
floating-point	O
types	O
,	O
but	O
also	O
pointer	O
types	O
,	O
and	O
compound	O
datatypes	O
(	O
unions	O
,	O
structs	B-Language
,	O
and	O
C++	B-Language
classes	O
)	O
.	O
</s>
<s>
Though	O
for	O
any	O
given	O
implementation	B-Application
of	O
C	B-Language
or	O
C++	B-Language
the	O
size	O
of	O
a	O
particular	O
datatype	O
is	O
constant	O
,	O
the	O
sizes	O
of	O
even	O
primitive	O
types	O
in	O
C	B-Language
and	O
C++	B-Language
may	O
be	O
defined	O
differently	O
for	O
different	O
platforms	O
of	O
implementation	B-Application
.	O
</s>
<s>
For	O
example	O
,	O
runtime	O
allocation	O
of	O
array	O
space	O
may	O
use	O
the	O
following	O
code	O
,	O
in	O
which	O
the	O
sizeof	B-Language
operator	O
is	O
applied	O
to	O
the	O
cast	O
of	O
the	O
type	O
int	O
:	O
</s>
<s>
int	O
*	O
pointer	O
=	O
malloc( 10	O
*	O
sizeof	B-Language
(	O
int	O
)	O
)	O
;	O
</s>
<s>
For	O
example	O
,	O
even	O
though	O
most	O
implementations	O
of	O
C	B-Language
and	O
C++	B-Language
on	O
32-bit	O
systems	O
define	O
type	O
int	O
to	O
be	O
four	O
octets	O
,	O
this	O
size	O
may	O
change	O
when	O
code	O
is	O
ported	O
to	O
a	O
different	O
system	O
,	O
breaking	O
the	O
code	O
.	O
</s>
<s>
The	O
exception	O
to	O
this	O
is	O
the	O
data	O
type	O
char	O
,	O
which	O
always	O
has	O
the	O
size	O
1	O
in	O
any	O
standards-compliant	O
C	B-Language
implementation	B-Application
.	O
</s>
<s>
In	O
addition	O
,	O
it	O
is	O
frequently	O
difficult	O
to	O
predict	O
the	O
sizes	O
of	O
compound	O
datatypes	O
such	O
as	O
a	O
struct	B-Language
or	O
union	O
,	O
due	O
to	O
padding	O
.	O
</s>
<s>
The	O
use	O
of	O
sizeof	B-Language
enhances	O
readability	O
,	O
since	O
it	O
avoids	O
unnamed	O
numeric	O
constants	O
(	O
magic	O
numbers	O
)	O
.	O
</s>
<s>
int	O
*	O
pointer	O
=	O
malloc( 10	O
*	O
sizeof	B-Language
*	O
pointer	O
)	O
;	O
</s>
<s>
The	O
operator	O
sizeof	B-Language
produces	O
the	O
required	O
memory	O
storage	O
space	O
of	O
its	O
operand	O
when	O
the	O
code	O
is	O
compiled	O
.	O
</s>
<s>
The	O
operand	O
is	O
written	O
following	O
the	O
keyword	O
sizeof	B-Language
and	O
may	O
be	O
the	O
symbol	O
of	O
a	O
storage	O
space	O
,	O
e.g.	O
,	O
a	O
variable	O
,	O
an	O
expression	O
,	O
or	O
a	O
type	O
name	O
.	O
</s>
<s>
For	O
example	O
,	O
since	O
sizeof	B-Language
(	O
char	O
)	O
is	O
defined	O
to	O
be	O
1	O
and	O
assuming	O
the	O
integer	O
type	O
is	O
four	O
bytes	O
long	O
,	O
the	O
following	O
code	O
fragment	O
prints	O
:	O
</s>
<s>
Certain	O
standard	O
header	B-Language
files	I-Language
,	O
such	O
as	O
stddef.h	O
,	O
define	O
size_t	O
to	O
denote	O
the	O
unsigned	B-Algorithm
integral	O
type	O
of	O
the	O
result	O
of	O
a	O
sizeof	B-Language
expression	O
.	O
</s>
<s>
sizeof	B-Language
cannot	O
be	O
used	O
in	O
C	B-Language
preprocessor	I-Language
expressions	O
,	O
such	O
as	O
,	O
because	O
it	O
is	O
an	O
element	O
of	O
the	O
programming	O
language	O
,	O
not	O
of	O
the	O
preprocessor	B-Application
syntax	O
,	O
which	O
has	O
no	O
data	O
types	O
.	O
</s>
<s>
The	O
following	O
example	O
in	O
C++	B-Language
uses	O
the	O
operator	O
sizeof	B-Language
with	O
variadic	B-Language
templates	I-Language
.	O
</s>
<s>
sizeof	B-Language
can	O
be	O
used	O
with	O
variadic	B-Language
templates	I-Language
in	O
C++11	O
and	O
above	O
on	O
a	O
parameter	O
pack	O
to	O
determine	O
the	O
number	O
of	O
arguments	O
.	O
</s>
<s>
When	O
sizeof	B-Language
is	O
applied	O
to	O
the	O
name	O
of	O
an	O
array	O
,	O
the	O
result	O
is	O
the	O
number	O
of	O
bytes	O
required	O
to	O
store	O
the	O
entire	O
array	O
.	O
</s>
<s>
This	O
is	O
one	O
of	O
the	O
few	O
exceptions	O
to	O
the	O
rule	O
that	O
the	O
name	O
of	O
an	O
array	O
is	O
converted	O
to	O
a	O
pointer	O
to	O
the	O
first	O
element	O
of	O
the	O
array	O
,	O
and	O
is	O
possible	O
just	O
because	O
the	O
actual	O
array	O
size	O
is	O
fixed	O
and	O
known	O
at	O
compile	O
time	O
,	O
when	O
the	O
sizeof	B-Language
operator	O
is	O
evaluated	O
.	O
</s>
<s>
The	O
following	O
program	O
uses	O
sizeof	B-Language
to	O
determine	O
the	O
size	O
of	O
a	O
declared	O
array	O
,	O
avoiding	O
a	O
buffer	B-General_Concept
overflow	I-General_Concept
when	O
copying	O
characters	O
:	O
</s>
<s>
C99	B-Language
adds	O
support	O
for	O
flexible	O
array	O
members	O
to	O
structures	O
.	O
</s>
<s>
In	O
this	O
case	O
the	O
sizeof	B-Language
operator	O
returns	O
the	O
size	O
of	O
the	O
structure	O
,	O
including	O
any	O
padding	O
,	O
but	O
without	O
any	O
storage	O
allowed	O
for	O
the	O
array	O
.	O
</s>
<s>
C99	B-Language
also	O
allows	O
variable	B-Data_Structure
length	I-Data_Structure
arrays	I-Data_Structure
that	O
have	O
the	O
length	O
specified	O
at	O
runtime	O
,	O
although	O
the	O
feature	O
is	O
considered	O
an	O
optional	O
implementation	B-Application
in	O
later	O
versions	O
of	O
the	O
C	B-Language
standard	O
.	O
</s>
<s>
In	O
such	O
cases	O
,	O
the	O
sizeof	B-Language
operator	O
is	O
evaluated	O
in	O
part	O
at	O
runtime	O
to	O
determine	O
the	O
storage	O
occupied	O
by	O
the	O
array	O
.	O
</s>
<s>
sizeof	B-Language
can	O
be	O
used	O
to	O
determine	O
the	O
number	O
of	O
elements	O
in	O
an	O
array	O
,	O
by	O
dividing	O
the	O
size	O
of	O
the	O
entire	O
array	O
by	O
the	O
size	O
of	O
a	O
single	O
element	O
.	O
</s>
<s>
At	O
this	O
point	O
,	O
sizeof	B-Language
will	O
return	O
the	O
size	O
of	O
the	O
pointer	O
,	O
not	O
the	O
total	O
size	O
of	O
the	O
array	O
.	O
</s>
<s>
sizeof	B-Language
can	O
only	O
be	O
applied	O
to	O
"	O
completely	O
"	O
defined	O
types	O
.	O
</s>
<s>
For	O
structs	B-Language
and	O
unions	O
,	O
this	O
means	O
that	O
there	O
must	O
be	O
a	O
member	O
list	O
of	O
completely	O
defined	O
types	O
.	O
</s>
<s>
Both	O
files	O
are	O
perfectly	O
legal	O
C	B-Language
,	O
and	O
code	O
in	O
can	O
apply	O
sizeof	B-Language
to	O
arr	O
and	O
.	O
</s>
<s>
If	O
the	O
programmer	O
provided	O
the	O
size	O
of	O
the	O
array	O
in	O
its	O
declaration	O
in	O
,	O
or	O
completed	O
the	O
definition	O
of	O
by	O
supplying	O
a	O
member	O
list	O
,	O
this	O
would	O
allow	O
the	O
application	O
of	O
sizeof	B-Language
to	O
arr	O
or	O
in	O
that	O
source	O
file	O
.	O
</s>
<s>
C++11	O
introduced	O
the	O
possibility	O
to	O
apply	O
the	O
sizeof	B-Language
parameter	O
to	O
specific	O
members	O
of	O
a	O
class	O
without	O
the	O
necessity	O
to	O
instantiate	O
the	O
object	O
to	O
achieve	O
this	O
.	O
</s>
<s>
C++11	O
introduced	O
variadic	B-Language
templates	I-Language
;	O
the	O
keyword	O
sizeof	B-Language
followed	O
by	O
ellipsis	O
returns	O
the	O
number	O
of	O
elements	O
in	O
a	O
parameter	O
pack	O
.	O
</s>
<s>
When	O
applied	O
to	O
a	O
fixed-length	O
datatype	O
or	O
variable	O
,	O
expressions	O
with	O
the	O
operator	O
sizeof	B-Language
are	O
evaluated	O
during	O
program	O
compilation	O
;	O
they	O
are	O
replaced	O
by	O
constant	O
result-values	O
.	O
</s>
<s>
The	O
C99	B-Language
standard	I-Language
introduced	O
variable-length	B-Data_Structure
arrays	I-Data_Structure
(	O
VLAs	O
)	O
,	O
which	O
required	O
evaluation	O
for	O
such	O
expressions	O
during	O
program	O
execution	O
.	O
</s>
<s>
In	O
many	O
cases	O
,	O
the	O
implementation	B-Application
specifics	O
may	O
be	O
documented	O
in	O
an	O
application	B-Operating_System
binary	I-Operating_System
interface	I-Operating_System
(	O
ABI	O
)	O
document	O
for	O
the	O
platform	O
,	O
specifying	O
formats	O
,	O
padding	O
,	O
and	O
alignment	O
for	O
the	O
data	O
types	O
,	O
to	O
which	O
the	O
compiler	O
must	O
conform	O
.	O
</s>
<s>
When	O
calculating	O
the	O
size	O
of	O
any	O
object	O
type	O
,	O
the	O
compiler	O
must	O
take	O
into	O
account	O
any	O
required	O
data	B-Application
structure	I-Application
alignment	I-Application
to	O
meet	O
efficiency	O
or	O
architectural	O
constraints	O
.	O
</s>
<s>
Many	O
computer	B-General_Concept
architectures	I-General_Concept
do	O
not	O
support	O
multiple-byte	O
access	O
starting	O
at	O
any	O
byte	O
address	O
that	O
is	O
not	O
a	O
multiple	O
of	O
the	O
word	O
size	O
,	O
and	O
even	O
when	O
the	O
architecture	O
allows	O
it	O
,	O
usually	O
the	O
processor	B-General_Concept
can	O
fetch	O
a	O
word-aligned	B-Application
object	I-Application
faster	O
than	O
it	O
can	O
fetch	O
an	O
object	O
that	O
straddles	O
multiple	O
words	O
in	O
memory	O
.	O
</s>
<s>
Thus	O
,	O
the	O
aggregate	O
size	O
of	O
a	O
structure	O
in	O
C	B-Language
can	O
be	O
greater	O
than	O
the	O
sum	O
of	O
the	O
sizes	O
of	O
its	O
individual	O
members	O
.	O
</s>
