영넌 개발로그
[C++ 기초] 데이터 타입 datatype _ 정수형 _ boolean 본문
정수형
- short 2byte
- int 4byte
- long 4byte
- long long 8byte (64bit)
* 부호 있냐 없냐에 따라 앞에 unsigned가 붙음 :: 크기는 같다!
!!! 표현하는 범위만 달라지는 것 !!!
프로그램을 통해 사이즈가 맞는지 확인해보자
#include <iostream>
int main()
{
using namespace std;
cout << "short size: " << sizeof(short) << endl;
cout << "int size: " << sizeof(int) << endl;
cout << "long size: " << sizeof(long) << endl;
cout << "long long size: " << sizeof(long long) << endl;
cout << endl;
short s_var;
int i_var;
long l_var;
long long ll_var;
//var name 이용
cout << "short size: " << sizeof s_var << endl;
cout << "int size: " << sizeof i_var << endl;
cout << "long size: " << sizeof l_var << endl;
cout << "long long size: " << sizeof ll_var << endl;
return 0;
}
* 각 데이터 타입의 최대 최소
헤더파일 climits 이용
#include <iostream>
#include <climits>
int main()
{
using namespace std;
cout << "short max: " << SHRT_MAX << endl;
cout << "short min: " << SHRT_MIN << endl;
return 0;
}
bool 데이터형
- true, false의 값을 가짐
- boolalpha 를 cout에 넣으면 true와 false가 나옴
- noboolalpha 를 cout에 넣으면 1과 0이 나옴 (default 값)
#include <iostream>
int main()
{
using namespace std;
bool b = true; // 1 넣어줘도 무관
bool c = false; // 0 넣어줘도 무관
cout << b <<" " << c << endl;
cout << boolalpha;
cout << b << " " << c << endl;
cout << noboolalpha;
cout << b << " " << c << endl;
return 0;
}
'코딩 > C++' 카테고리의 다른 글
[C++ 기초] 데이터 타입 datatype _실수형 _문자형 (2) | 2020.10.06 |
---|---|
[C++ 기초] 변수 초기화 initialization (0) | 2020.10.06 |
[C ++ 기초] 함수 만들기 / sqrt() / <cmath> (0) | 2020.10.06 |
[C++ 기초] Hello World! 출력하기 / 변수 입력받기 (0) | 2020.09.30 |
Comments