- bool 자료형
- 1byte
- 0 or 1
- 0 이 아닌 모든 정수를 1로 저장
- false(0), true(1)로 사용됨
#include <stdio.h>
#include <iostream>
#include <iomanip>
using namespace std;
bool isBiggerBthanA(int a, int b) {
if (a < b)
return true;
else
return false;
}
void main() {
cout << isBiggerBthanA(10, 5) << endl;
bool a = 100;
bool b = -100;
// 0이 아닌 정수는 전부 1로 처리됨
cout << "a : " << a << "\nb : " << b << endl;
}
isBiggerBthanA 에서는 5는 10보다 작으므로 false(0) 출력
100(양수), -100(음수) 상관없이 0이 아니므로 1 출력
'C++ > 기초' 카테고리의 다른 글
[C++] 동적할당 (1) | 2023.12.18 |
---|---|
[C++] 래퍼런스(Reference) 변수, 포인터(Pointer) 변수 (0) | 2023.12.15 |
[C++] 오버로딩, 디폴트 매개변수, 초기화 (0) | 2023.12.14 |
[C++] namespace (0) | 2023.12.14 |
[C++] cin, cin.get, cout, fflush (0) | 2023.12.14 |