리눅스 프로그래밍/C++

변수형 크기 / 형식 지정자

삽질중 2013. 11. 3. 15:53

통상적으로 프로그램 할때 항상 사용하는 디파인이다.. 쓰다보면 편해서 이렇게 사용한다.. 그냥 참고용


//정수형

//8Bit

typedef unsigned char uchar;  //(0 ~ 255)

typedef unsigned char uint8;  //(0 ~ 255)

typedef    signed char sint8;  // (-128 ~ 127)


//16Bit

typedef unsigned short uint16; //(0 ~ 65535)

typedef    signed short sint16; // (-32768 ~ 32767)


//32Bit

typedef unsigned int uint32; // (0 ~ 4294967295)

typedef    signed int sint32; // (-2147484648 ~ 2147483647)

                                                        


//64Bit

typedef unsigned long     uint64; //  (0 ~ 18446744073709551615)

typedef    signed long     sint64; // (-9223372036854775808 ~ 9223372036854775807)


//실수형 참고

short    2Byte

float     4Byte

double  8Byte



*printf() 또는 scanf() 사용시 형식 지정자


%d : signed int 10진수 출력

%u : unsigned int 10진수로 출력

%l  : long형으로 출력  (ex : uint64의 경우 %lu, sint64의 경우 %ld)

%h : short형으로 출력

%f  : 실수형으로 출력

%o : 8진수로 출력

%x : 16진수로 출력