Solution for Exercise 18-1
ex1801
#include <stdio.h>
int main()
{
char c = 'c';
int i = 123;
float f = 98.6;
double d = 6.022E23;
printf("char\t%u\n",sizeof(c));
printf("int\t%u\n",sizeof(i));
printf("float\t%u\n",sizeof(f));
printf("double\t%u\n",sizeof(d));
return(0);
}
Notes
* I didn't need to assing values to the variables in Lines 5 through 8; the sizeof operator works on variables whether they're initialized or not.
* The %u conversion character is required to report the unsigned int value returned by sizeof.
* Some compilers may let you use the %zd conversion character, which is designed to display size_t variables returned by sizeof.
* On the off-chance that you're using a Macintosh, or some other Unix variant, you'll need to change the conversion character used in printf() Lines 10 through 13 to %ld. On those systems, the sizeof operator returns a long int value.
Copyright © 1997-2025 by QPBC.
All rights reserved
