[C/C++/Algorithm] Size of Data Type

2주 정도 전에 Programming 시험을 쳤다. 다행히 문제를 풀기는 했는데, Data Type들의 사이즈를 헷갈려서 printf 함수를 사용해서 가능 범위를 확인하고 문제를 풀 수 있었다. 그래서 간단하게 Data Type들의 출력 가능 범위를 짧게 정리해보았다.

TypeStorage SizeValue Range
char1 Byte-128 ~ 127 or 0 ~ 255
unsigned char1 Byte0 ~ 255
signed char1 Byte-128 ~ 127
int2 Bytes or 4 Bytes-32,768 ~ 32,767 or -2,147,483,648 ~ 2,147,483,647
unsigned int2 Bytes or 4 Bytes0 ~ 65,535 or 0 ~ 4,294,967,295
short2 Bytes-32,768 ~ 32,767
long4 Bytes-2,147,483,648 ~ 2,147,483,647
unsigned long4 Bytes0 ~ 4,294,967,295
float4 Bytes1.2E-38 ~ 3.4E+38 (6 Decimal Places)
double8 Bytes2.3E-308 ~ 1.7E+308 (15 Decimal Places)
long double10 Bytes3.4E-4932 ~ 1.1E+4932 (19 Decimal Places)

위 내용은 당연히 알아야 하는 정도의 기본인지도 모르겠다 (어쩌면 기본도 없이 Programming 시험을 보러 다녔는지도 모르겠다).

출처

  1. https://intellipaat.com/tutorial/c-tutorial/c-data-types/
  2. https://www.tutorialspoint.com/cprogramming/c_data_types.htm

Leave a Comment