C语言,数据类型
#include <stdio.h> void f0(void) { printf("in linux:\n"); printf("sizeof(char) = %d\n", sizeof(char)); printf("sizeof(int) = %d\n", sizeof(int)); printf("sizeof(short int) = %d\n", sizeof(short int)); printf("sizeof(long int) = %d\n", sizeof(long int)); printf("sizeof(float) = %d\n", sizeof(float)); printf("sizeof(double) = %d\n", sizeof(double)); printf("sizeof(long double) = %d\n", 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\n", i, ui); printf("for 1, c = %x, uc = %x\n", c, uc); printf("for 1, si = %x, usi = %x\n", si, usi); printf("for 1, f = %x\n", f); printf("for 1, d = %x\n", d); printf("for 1, ld = %x\n", 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\n", i, ui); printf("for -1, c = %x, uc = %x\n", c, uc); printf("for -1, si = %x, usi = %x\n", si, usi); printf("for -1, f = %x\n", f); printf("for -1, d = %x\n", d); printf("for -1, ld = %x\n", ld); c = -255; uc = -255; printf("for -255, c = %x, uc = %x\n", c, uc); c = -128; uc = -128; printf("for -128, c = %x, uc = %x\n", c, uc); } void f_show1(void) { printf("for -1,f_show1: uint = %x\n", (unsigned int)-1); printf("for -1,f_show1: int = %x\n", (int)-1); printf("for -1,f_show1: c = %x\n", (char)-1); printf("for -1,f_show1: uc = %x\n", (unsigned char)-1); printf("for -1,f_show1: uc = %d\n", (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 */