[TIL] 따배씨 15일차
논리연산자 3_6
#include <iostream>
int main()
{
	using namespace std;
	//logical and
	bool x = true;
	bool y = false;
	cout << (x && y) << endl;
	cout << (x || y) << endl;
	bool hit = true;
	int health = 10;
	if (hit == true && health < 20)
	{
		cout << "die" << endl;
	}
	int v = 1;
	if (v == 0 || v == 1)
		cout << "v is 0 or 1 " << endl;
	// short circuit evaluation
	int x = 2;
	int y = 2;
	if (x == 1 && y++ == 2) // x ==1 에서 넘어가지 못하고 y가 ++ 동작이 불가능해진다.
	{
		//do something
	}
	cout << y << endl;
	bool z = true;
	bool k = false;
	// De Morgan's Law
	!(x && y);
	!x || !y; // 분배의 법칙이 적용 x
	!(x || y); //이것을 풀어서 쓰면 아래처럼 적용
	!x && !y;
	//XOR
	//flase false false
	//false true true
	//true false true
	//true true false 
	if (z != k)//XOR 
	{
	}
	bool v1 = true;
	bool v2 = false;
	bool v3 = false;
	bool r1 = v1 || v2 && v3;
	bool r2 = (v1 || v2) && v3;
	bool r3 = v1 || (v2 && v3); // &&가 ||보다 우선순위가 높다.
	cout << r1 << endl;
	cout << r2 << endl;
	return 0;
}
                Author And Source
이 문제에 관하여([TIL] 따배씨 15일차), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@jeus95/TIL-따배씨-15일차저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)