BUPT-homework/pset1/5-data-types.c
2021-09-26 11:19:13 +08:00

28 lines
826 B
C

#include <stdio.h>
int main(void) {
// initialize variables
char a;
short b;
int c;
long d;
long long e;
float f;
double g;
// assign values from stdin
scanf("%c %hd %i %ld %lld %f %lf", &a, &b, &c, &d, &e, &f, &g);
// print answers
printf("The 'char' variable is %c, it takes %ld byte.\n", a, sizeof(a));
printf("The 'short' variable is %hd, it takes %ld bytes.\n", b, sizeof(b));
printf("The 'int' variable is %i, it takes %ld bytes.\n", c, sizeof(c));
printf("The 'long' variable is %ld, it takes %ld bytes.\n", d, sizeof(d));
printf("The 'long long' variable is %lld, it takes %ld bytes.\n", e,
sizeof(e));
printf("The 'float' variable is %f, it takes %ld bytes.\n", f, sizeof(f));
printf("The 'double' variable is %lf, it takes %ld bytes.\n", g, sizeof(g));
return 0;
}