▶자료형: 데이터의 타입
- 정수형 데이터 : short, int, long, long long
- 실수형 데이터 : float, double, long double
- 문자형 데이터 : char, string
- bool형 데이터: bool {True or False}
1) 정수형
Type Name | Short Name | Storage | Smallest Magnitude | Largest Magnitude |
short int | short | 2 bytes | −215 | 215−1 |
int | int | 4 bytes | −231 | 231−1 |
long int | long | 4 bytes | −231 | 231−1 |
long long int | long long | 8 bytes | −263 | 263−1 |
unsigned short | unsigned short | 2 bytes | 0 | 216−1 |
unsigned int | unsigned | 4 bytes | 0 | 232−1 |
unsigned long | unsigned long | 4 bytes | 0 | 232−1 |
unsigned long long | unsigned long long | 8 bytes | 0 | 264−1 |
2) 실수형
Type Name | Minimum Precision | Storage | Smallest Magnitude | Largest Magnitude |
float | 6 digits | 4 bytes | 1.17549×10−38 | 3.40282×1038 |
double | 15 digits | 8 bytes | 2.22507×10−308 | 1.79769×10308 |
long double | 15 digits | 8 bytes | 2.22507×10−308 | 1.79769×10308 |
3) 문자형
Type Name | Storage | Implementation | 특징 |
char | 1 byte | char b = 'A' cf) char b = "A" (x) cf) char b = 'Hello' (x) |
단일 문자형만 가능 반드시 작은 따옴표 사용 |
string | 길이에 따라 달라짐 | string str1 = "B" string str2 = "Hello" cf) string str3 = 'B' (x) |
단일 문자형, 큰 문자형 반드시 큰 따옴표 사용 |
4) bool 형
Type Name | Type | Binary Value |
bool | True | 1 |
False | 0 |
5) const 제한자
'const'는 바뀔 필요가 없거나 바뀌어서는 안 되는 수를 정의하려고 할 때 사용하는 제한자이다.
예시)
- 원의 넓이를 구할 때: const pi = 3.141592
- 학점의 최댓값을 설정할 때: const max_score = 4.3
'Programming > C++' 카테고리의 다른 글
[C++ 기초] C++ 연산자 종류 (0) | 2024.03.21 |
---|---|
[C++ 기초] auto의 사용법 (3) | 2024.03.21 |
[C++ 기초] 변수 선언과 규칙 (1) | 2024.02.05 |
[C++ 기초] C++ 기본사항 (1) | 2024.02.05 |