별의 공부 블로그 🧑🏻‍💻
728x90
728x170

C++의 자료형(Data Type)

  • C++ 의 자료형에는 기본형, 문자형, 정수형, 실수형(부동 소수점형)이 있다.
    • 기본형
      • void
    • 문자형
      • (singed) char
      • unsigned char
      • wchar_t
    • 정수형
      • bool
      • (signed) short (int)
      • unsigned short (int)
      • (signed) int
      • unsigned int
      • (signed) long (int)
      • unsigned long (int)
      • __int8
      • __int16
      • __int32
      • __int64
    • 실수형(부동 소수점형)
      • float
      • (long) double

 

정수 자료형의 크기 및 범위 (LLP64/IL32P64, Windows)

자료형 크기 범위 비고
char
signed char
1 Byte
8 Bits
-128 ~ 127  
unsigned char 1 Byte, 8 Bits 0 ~ 255  
short
short int
2 Bytes
16 Bits
-32,768 ~ 32,767 int 생략 가능
unsigned short
unsigned short int
2 Bytes
16 Bits
0 ~ 65,535 int 생략 가능
int
signed int
4 Bytes
32 Bits
-2,147,483,648 ~ 2,147,483,647  
unsigned
unsigned int
4 Bytes
32 Bits
0 ~ 4,294,967,295 int 생략 가능
long
long int
signed long
signed long int
4 Bytes
32 Bits
-2,147,483,648 ~ 2,147,483,647 int 생략 가능
unsigned long
unsigned long int
4 Bytes
32 Bits
0 ~ 4,294,967,295 int 생략 가능
long long
long long int
signed long long
signed long long int
8 Bytes
64 Bits
-9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 int 생략 가능
unsigned long long
unsigned long long int
8 Bytes
64 Bits
0 ~ 18,446,744,073,709,551,615 int 생략 가능

 

자료형의 크기 및 범위 (Microsoft Visual C++)

Type Name Bytes Other Names Range of Values
int * signed
signed int
System Dependent
unsigned int * unsigned System Dependent
__int8 1 char
signed char
-128 to 127
__int16 2 short
short int
signed short int
–32,768 to 32,767
__int32 4 signed
signed int
–2,147,483,648 to 2,147,483,647
__int64 8 none –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
bool 1 none false or true
char 1 signed char –128 to 127
unsigned char 1 none 0 to 255
long 4 long int
signed long int
–2,147,483,648 to 2,147,483,647
long long 8 none
(but equivalent to __int64)
–9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
unsigned long 4 unsigned long int 0 to 4,294,967,295
unsigned long long 8 unsigned long long int 0 to 18,446,744,073,709,551,615
enum * none Same as int
float 4 none 3.4E +/- 38 (7 digits)
double 8 none 1.7E +/- 308 (15 digits)
long double 8 none same as double
wchar_t 2 __wchar_t 0 to 65,535

※ float 형은 소수점 최대 7자리까지, double 형, long double 형은 소수점 최대 15자리까지의 정확성을 보장한다.

※ A variable of __wchar_t designates a wide-character or multibyte character type.

※ By default wchar_t is a typedef for unsigned short.

 

참고

https://melonicedlatte.com/algorithm/2018/03/04/022437.html

 

C/C++ 에 존재하는 모든 자료형 개념 총 정리 - Easy is Perfect

알고리즘 문제 풀이 시에, 모르는 게 많이 생기게 됩니다. 특히 자료형에 대한 게 많이 헷갈리는 경우가 존재합니다. 어떤 문제는 long long 자료형을 써야할 때가 있고 (int 형의 범위를 초과해서)

melonicedlatte.com

 

728x90
그리드형(광고전용)
⚠️AdBlock이 감지되었습니다. 원할한 페이지 표시를 위해 AdBlock을 꺼주세요.⚠️
starrykss
starrykss
별의 공부 블로그 🧑🏻‍💻


📖 Contents 📖