반응형
C++ 자료형 일부 정리
C++에 있는 자료형의 최대값과 최소값을 확인해보자
모든 자료형을 다루지는 않고 자주 사용하는 정수형 자료형의 크기를 출력해보자.
#include <iostream>
#include <stdio.h>
#include <limits>
using namespace std;
int main() {
int int_MAX = INT_MAX;
int int_MIN = INT_MIN;
int Uint_MAX = UINT_MAX;
printf("Maximum value of INT : %d\n", int_MAX);
printf("Minimum value of INT : %d\n", int_MIN);
printf("Maximum value of Unsigned INT : %u\n", Uint_MAX);
printf("\n");
short int Sint_MAX = SHRT_MAX;
short int Sint_MIN = SHRT_MIN;
unsigned short int USint_MAX = USHRT_MAX;
printf("Maximum value of Short INT : %ld\n", Sint_MAX);
printf("Minimum value of Short INT : %ld\n", Sint_MIN);
printf("Maximum value of Unsigned Short INT : %lu\n", USint_MAX);
printf("\n");
long int Lint_MAX = LONG_MAX;
long int Lint_MIN = LONG_MIN;
unsigned long int ULint_MAX = ULONG_MAX;
printf("Maximum value of Long INT : %ld\n", Lint_MAX);
printf("Minimum value of Long INT : %ld\n", Lint_MIN);
printf("Maximum value of Unsigned Long INT : %lu\n", ULint_MAX);
printf("\n");
long long int LLint_MAX = LLONG_MAX;
long long int LLint_MIN = LLONG_MIN;
unsigned long long int ULLint_MAX = ULLONG_MAX;
printf("Maximum value of Long Long INT : %lld\n", LLint_MAX);
printf("Minimum value of Long Long INT : %lld\n", LLint_MIN);
printf("Maximum value of Unsigned Long Long INT : %llu\n", ULLint_MAX);
printf("\n");
double d_MAX = DBL_MAX;
double d_MIN = DBL_MIN;
printf("Maximum value of double : %lf\n", d_MAX);
printf("Maximum value of double : %0.5e\n", d_MAX);
printf("Minimum value of double : %0.5e\n", d_MIN);
printf("\n");
// 아래와 같이 표준라이브러리의 numeric_limits을 사용할 수도 있다
puts("<STL numeric_limits 사용>\n");
printf("Maximum value of int : %d\n", numeric_limits<int>::max());
printf("Minimum value of int : %d\n", numeric_limits<int>::min());
printf("\n");
printf("Maximum value of __int8 : %d\n", numeric_limits<__int8>::max());
printf("Minimum value of __int8 : %d\n", numeric_limits<__int8>::min());
printf("\n");
printf("Maximum value of __int16 : %d\n", numeric_limits<__int16>::max());
printf("Minimum value of __int16 : %d\n", numeric_limits<__int16>::min());
printf("\n");
printf("Maximum value of __int32 : %d\n", numeric_limits<__int32>::max());
printf("Minimum value of __int32 : %d\n", numeric_limits<__int32>::min());
printf("\n");
printf("Maximum value of __int64 : %lld\n", numeric_limits<__int64>::max());
printf("Minimum value of __int64 : %lld\n", numeric_limits<__int64>::min());
printf("\n");
printf("Maximum value of float : %f\n", numeric_limits<float>::max());
printf("Maximum value of float : %0.5e\n", numeric_limits<float>::max());
printf("Minimum value of float : %0.5e\n", numeric_limits<float>::min());
printf("\n");
printf("Maximum value of double : %lf\n", numeric_limits<double>::max());
printf("Maximum value of double : %0.5e\n", numeric_limits<double>::max());
printf("Minimum value of double : %0.5e\n", numeric_limits<double>::min());
printf("\n");
return 0;
}
출력 결과는 아래와 같다.
Maximum value of INT : 2147483647 Minimum value of INT : -2147483648 Maximum value of Unsigned INT : 4294967295 Maximum value of Short INT : 32767 Minimum value of Short INT : -32768 Maximum value of Unsigned Short INT : 65535 Maximum value of Long INT : 2147483647 Minimum value of Long INT : -2147483648 Maximum value of Unsigned Long INT : 4294967295 Maximum value of Long Long INT : 9223372036854775807 Minimum value of Long Long INT : -9223372036854775808 Maximum value of Unsigned Long Long INT : 18446744073709551615 Maximum value of double : 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000 Maximum value of double : 1.79769e+308 Minimum value of double : 2.22507e-308 <STL numeric_limits 사용> Maximum value of int : 2147483647 Minimum value of int : -2147483648 Maximum value of __int8 : 127 Minimum value of __int8 : -128 Maximum value of __int16 : 32767 Minimum value of __int16 : -32768 Maximum value of __int32 : 2147483647 Minimum value of __int32 : -2147483648 Maximum value of __int64 : 9223372036854775807 Minimum value of __int64 : -9223372036854775808 Maximum value of float : 340282346638528859811704183484516925440.000000 Maximum value of float : 3.40282e+38 Minimum value of float : 1.17549e-38 Maximum value of double : 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000 Maximum value of double : 1.79769e+308 Minimum value of double : 2.22507e-308 |
<Reference>
- https://jacking.tistory.com/1028
- https://www.geeksforgeeks.org/maximum-value-of-long-long-int-in-c/
- https://www.cplusplus.com/reference/cstdio/printf/
- https://www.delftstack.com/ko/howto/cpp/int_max-in-cpp/
- http://melonicedlatte.com/algorithm/2018/03/04/022437.html
반응형
'Data science > 알고리즘 학습' 카테고리의 다른 글
SWEA 5604 : 구간합[D4] (C++) (0) | 2022.03.30 |
---|---|
SWEA 1232 : 사칙연산[D4] (C++) (0) | 2022.03.28 |
SWEA 1251 : 하나로[D4] (c++)_(priority_queue) (0) | 2022.02.23 |
그래프 알고리즘 (0) | 2022.02.22 |
SWEA 1251 : 하나로[D4] (c++) (0) | 2022.02.13 |