C++ Chapter 02. C언어 기반의 C++ 2. 02-2 새로운 자료형 bool
C,C++/CONCEPT 2018. 2. 28. 09:21 |C++ Chapter 02. C언어 기반의 C++ 2.
02-2 새로운 자료형 bool
* '참'을 의미하는 true와 '거짓'을 의미하는 false
// true와 false는 각각 1과 0을 의미하는 키워드가 아니다
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <iostream> using namespace std; int main(void) { int num=10; int i=0; cout<<"true: "<<true<<endl; // 1 cout<<"false: "<<false<<endl; // 0 while(true) { cout<<i++<<' '; if(i>num) break; } cout<<endl; // 0 1 2 3 4 5 6 7 8 9 10 cout<<"sizeof 1: "<<sizeof(1)<<endl; // 4 cout<<"sizeof 0: "<<sizeof(0)<<endl; // 4 cout<<"sizeof true: "<<sizeof(true)<<endl; // 1 cout<<"sizeof false: "<<sizeof(false)<<endl; // 1 return 0; } | cs |
* 자료형 bool
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include <iostream> using namespace std; bool IsPositive(int num) { if(num<0) return false; else return true; } int main(void) { bool isPos; int num; cout<<"Input number: "; cin>>num; isPos=IsPositive(num); if(isPos) cout<<"Positive number"<<endl; else cout<<"Negative number"<<endl; return 0; } | cs |
'C,C++ > CONCEPT' 카테고리의 다른 글
C++ Chapter 02. C언어 기반의 C++ 2. 02-4 참조자(Reference)와 함수 (0) | 2018.02.28 |
---|---|
C++ Chapter 02. C언어 기반의 C++ 2. 02-3 참조자(Reference)의 이해 (0) | 2018.02.28 |
C++ Chapter 02. C언어 기반의 C++ 2. 02-1 Chapter 02의 시작에 앞서 (0) | 2018.02.28 |
C++ Chapter 01. C언어 기반의 C++ 1. 01-5 이름공간(namespace)에 대한 소개 (0) | 2018.02.28 |
C++ Chapter 01. C언어 기반의 C++ 1. 01-4 인라인(inline) 함수 (0) | 2018.02.28 |