독개

#따배씨 불리언 자료형과 조건문 if

by #독개#

 

true (1)
false (0)

컴퓨터는 0 , 1 로만 받아들인다

if(a) ---- if 문은 0을 제외한 모든 값을 참으로 받아들인다

 

#include <iostream>
#include <iomanip>
#include <cmath>

int main()
{
	using namespace std;	
	//bool b1 = 1; 이랑 같다 (컴퓨터 내부적으로는 true==1 false==0 로만 생각한다)
	bool b1 = true;		//copy initialization
	bool b2(false);		//direct ""
	bool b3{ true };	//uniform ""
	b3 = false;

	cout << b3 << endl;		//출력0
	cout << b1 << endl;		//출력1
	cout << std::boolalpha; //앞으로는 아래부터 출력을 true, false 문자로 출력하겠다
	cout << b3 << endl;		//출력 true
	cout << b1 << endl;		//출력 false
	cout << std::noboolalpha; //앞으로는 아래부터 출력을 문자로 안하겠다
	cout << !b3 << endl;	//출력 1
	cout << !b1 << endl;	//출력 0
	return 0;

	//논리연산자 && || 두개는 아는거라 기록안함
	

	//! if(a) if문은 안에 조건이 0인거 외에 모든값을 true로 본다
}

 

 

 

 


🐱‍👓독하게 개발

 

블로그의 정보

독한 개발자

#독개#

활동하기