[Courses] [C] Lesson Three: Basic Declarations & Expressions
Anca M. Holban
anca at lsv.cl.edu.ro
Thu Oct 10 18:14:26 EST 2002
>Here is a small program that will use the 'sizeof' operator to
>show exactly how much memory is reserved for some commonly used
>variable types.
>
> /* var-size.c -- variable type and sizeof each one */
> #include <stdio.h>
>
> int main(void)
> {
> /* variable declarations */
> int variable_1; /* an integer variable type */
> float variable_2; /* a floating point variable */
> double variable_3; /* a double precision variable */
>
> /* output of sizeof each variable type */
> printf("%d\n", sizeof(variable_1));
> printf("%d\n", sizeof(variable_2));
> printf("%d\n", sizeof(variable_3));
>
> return 0;
> }
I'd do smth like this:
#include "stdio.h"
int main(void)
{
printf("%d\n",sizeof(int));
printf("%d\n",sizeof(float));
printf("%d\n",sizeof(double));
return 0;
}
More information about the Courses
mailing list