Pages

June 06, 2010

Size of

The sizeof() operator evaluates to the size of a type in bytes. The sizeof operator (without the parentheses) evaluates to the size of a variable, object or expression in bytes. For example,


 /* Type Sizes
* sizeof.c
* May 14 2007
*/

#include

int main(void) {
double x;
printf("On this machine, \n"
"the size of an int is %d bytes,\n"
"the size of x is %d bytes.\n",
sizeof(int), sizeof x );
return 0;
}










On this machine,
the size of an int is 4 bytes,
the size of x is 8 bytes.




Note that sizeof() takes a type, while sizeof takes a variable, object or expression. With some compilers, the two operators are interchangeable.


int type

An int type occupies one word of memory. One word is typically the size of a CPU register, making the int type the optimally efficient type. On 32-bit platforms, one word spans 4 bytes:

No comments:

Post a Comment