Type | Bytes | Range | Fixed-width types |
---|---|---|---|
bool | 1 | true, false | |
char | 1 | implementation defined | |
signed char | 1 | -128 to 127 | int8_t |
unsigned char | 1 | 0 to 255 | uint8_t |
short | 2 | -2^15 to 2^15-1 | int16_t |
unsigned short | 2 | 0 to 2^16-1 | uint16_t |
int | 4 | -2^31 to 2^31-1 | int32_t |
unsigned int | 4 | 0 to 2^32-1 | uint32_t |
long int | 4/8 | int32_t/int64_t | |
long unsigned int | 4/8 | uint32_t/uint64_t | |
long long int | 8 | -2^63 to 2^63-1 | int64_t |
long long unsigned int | 8 | 0 to 2^64-1 | uint64_t |
float (IEEE 754) | 4 | ±1.18 × 10^(-38) to ±3.4 × 10^(+38) | |
double (IEEE 754) | 8 | ±2.23 × 10^(-308) to ±1.8 × 10^(+308) |
Signed Type | Short Name ⭐ | Unsigned Type | Short Name ⭐ |
---|---|---|---|
signed char | / | unsigned char | / |
signed short int | short | unsigned short int | unsigned short |
signed int | int | unsigned int | unsigned |
signed long int | long | unsigned long int | unsigned long |
signed long long int | long long | unsigned long long int | unsigned long long |
⚠️
unsigned int = 3;
과 같이, 리터럴을 붙이지 않는 경우 형변환이 일어나 int형의 3이 unsigned int형의 3으로 변환되게 되므로 주의해야한다.
Type | SUFFIX | Example | Notes |
---|---|---|---|
int | 2 | 리터럴 없음(작성 불필요) | |
unsigned int | u, U | 3u | |
long int | i, L | 8L | |
long unsigned | ul, UL | 2ul | |
long long int | ll, LL | 4ll | |
long long unsigned int | ull, ULL | 7ULL | |
float | f, F | 3.0f | only decimal numbers(10진법) |
double | 3.0 | only decimal numbers(10진법) |
.
Representation | PREFIX | Example |
---|---|---|
Binary(이진법) C++14 | 0b | 0b010101 |
Octal(팔진법) | 0 | 0307 |
Hexadecimal(16진법) | 0x or 0X | 0xFFA010 |
[참고]
C++14
는 가독성 개선을 위해 숫자 구분 기호를 넣는 것을 허용함float pi = 3.141'592'654'5f; //3단위 씩 끊어서 쓸 수 있음.
void
typevoid는 값이 없는 불완전한(정의되지 않은) 유형이다.
void f()
, f(void)
void 반환 유형(Return Type): C++에서 void는 함수가 값을 반환하지 않음을 나타내는 리턴 타입을 나타낸다.
매개변수 없는 함수(No Parameters): 매개변수를 가지지 않을 때
void example_1() {
// this function does not return any value!
}
int example_2() {
// this function does not require any parameter!
}
sizeof(void) == 1
이지만, C++에선 sizeof(void)
가 컴파일되지 않으니 주의해야함int main() {
//sizeof(void); //compile error
}
nullptr
keywordC언어
int* p = NULL;
C++
int* p = nullptr;
참고
int* p1 = NULL; // ok, equal to int* p1 = 0l
int* p2 = nullptr; // ok, nullptr is a pointer not a number
int n1 = NULL; // ok, we are assigning 0 to n1
// int n2 = nullptr; // compile error we are assigning
// a null pointer to an integer variable
int *p2 = true ? 0 : nullptr; // compile error
// incompatible types