C言語、データ型
3661 ワード
#include <stdio.h>
void f0(void)
{
printf("in linux:
");
printf("sizeof(char) = %d
", sizeof(char));
printf("sizeof(int) = %d
", sizeof(int));
printf("sizeof(short int) = %d
", sizeof(short int));
printf("sizeof(long int) = %d
", sizeof(long int));
printf("sizeof(float) = %d
", sizeof(float));
printf("sizeof(double) = %d
", sizeof(double));
printf("sizeof(long double) = %d
", sizeof(long double));
}
void f1(void)
{
int i = 1;
unsigned int ui = 1;
char c = 1;
unsigned char uc = 1;
short int si = 1;
unsigned short int usi = 1;
float f = 1;
double d = 1;
long double ld = 1;
printf("for 1, i = %x, ui = %x
", i, ui);
printf("for 1, c = %x, uc = %x
", c, uc);
printf("for 1, si = %x, usi = %x
", si, usi);
printf("for 1, f = %x
", f);
printf("for 1, d = %x
", d);
printf("for 1, ld = %x
", ld);
}
void f2()
{
int i = -1;
unsigned int ui = -1;
char c = -1;
unsigned char uc = -1;
short int si = -1;
unsigned short int usi = -1;
float f = -1;
double d = -1;
long double ld = -1;
printf("for -1, i = %x, ui = %x
", i, ui);
printf("for -1, c = %x, uc = %x
", c, uc);
printf("for -1, si = %x, usi = %x
", si, usi);
printf("for -1, f = %x
", f);
printf("for -1, d = %x
", d);
printf("for -1, ld = %x
", ld);
c = -255;
uc = -255;
printf("for -255, c = %x, uc = %x
", c, uc);
c = -128;
uc = -128;
printf("for -128, c = %x, uc = %x
", c, uc);
}
void f_show1(void)
{
printf("for -1,f_show1: uint = %x
", (unsigned int)-1);
printf("for -1,f_show1: int = %x
", (int)-1);
printf("for -1,f_show1: c = %x
", (char)-1);
printf("for -1,f_show1: uc = %x
", (unsigned char)-1);
printf("for -1,f_show1: uc = %d
", (unsigned char)-1);
}
int main()
{
f0();
f_show1();
f1();
f2();
return 0;
}
/*
root@oucaijun:/work/dcc# gcc 1.c ;./a.out
in linux:
sizeof(char) = 1
sizeof(int) = 4
sizeof(short int) = 2
sizeof(long int) = 4
sizeof(float) = 4
sizeof(double) = 8
sizeof(long double) = 12
// linux , ?
for -1,f_show1: uint = ffffffff
for -1,f_show1: int = ffffffff
for -1,f_show1: c = ffffffff
for -1,f_show1: uc = ff
for -1,f_show1: uc = 255
for 1, i = 1, ui = 1
for 1, c = 1, uc = 1
for 1, si = 1, usi = 1
for 1, f = 0
for 1, d = 0
for 1, ld = 0
for -1, i = ffffffff, ui = ffffffff
for -1, c = ffffffff, uc = ff
for -1, si = ffffffff, usi = ffff
for -1, f = 0
for -1, d = 0
for -1, ld = 0
for -255, c = 1, uc = 1
for -128, c = ffffff80, uc = 80
*/