Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 27 | 28 |
Tags
- web
- greedy
- Cleancode
- udemy
- 종만북
- Algorithm
- Python
- Math
- sorting
- BFS
- programmers
- C언어
- String
- php
- server
- 생활코딩
- BASIC
- 따라하면서 배우는 C언어
- graph
- C
- BOJ
- 백준
- 인프런
- JavaScript
- Algospot
- 정수론
- 따배씨
- dfs
- 따라하며 배우는 C언어
- DP
Archives
- Today
- Total
몽상실현개발주의
[따배씨] 7.7 논리 연산자 본문
따배씨 - 따라하며 배우는 C언어
7강 분기
7.7 논리 연산자 Logical operators
#include <stdio.h>
#include <stdbool.h>
int main(){
bool test1 = 3 > 2 || 5 > 6; // true
bool test2 = 3 > 2 && 5 > 6; // false
bool test3 = !(5 > 6); // treu, equivalent to 5 <= 6
printf("%d %d %d\n", test1, test2, test3);
// 1 0 1
return 0;
}
#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>
#define PERIOD '.'
int main(){
char ch;
int count = 0;
while ((ch = getchar()) != PERIOD)
{
if (ch != '\n' && ch != ' ')
{
count++;
}
}
printf("%d\n", count);
return 0;
}
#include <stdio.h>
#include <stdbool.h>
#include <iso646.h>
int main(){
bool test1 = 3 > 2 or 5 < 6; //true
bool test2 = 3 > 2 and 5 > 6; // false
bool test3 = not(5 > 6);
printf("%d %d %d\n", test1, test2, test3);
// 1 0 1
return 0;
}
- ios646.h 헤더를 사용하면 or, and, not 으로 사용가능
- || == or
- && == and
- != == not
#include <stdio.h>
int main(){
/*
Short-circuit Evaluation
- Logical expressions are evaluated from left to right
- && and || are sequence points
*/
int temp = (1 + 2) * (3 + 4);
printf("Before : %d\n", temp);
if (temp == 0 && (++temp == 1024))
{
//do nothing
};
printf("After : %d\n", temp);
return 0;
}
- Short-circuit Evaluation
- && 와 || 는 Sequence point
- temp == 0 && (++temp == 1024)
- && 왼쪽의 연산이 참일 경우에만, && 오른쪽의 연산 수행
- || 의 경우
- 왼쪽이 참이면, || 오른쪽 확인 X
- 왼쪽이 거짓일 경우에만, || 오른쪽 확인
이 글의 모든 사진과 내용의 출처는 홍정모 교수님께 있음을 알려드립니다.
'Language > C' 카테고리의 다른 글
[따배씨] 7.9 조건 연산자 (0) | 2021.05.24 |
---|---|
[따배씨] 7.8 단어 세기 예제 (0) | 2021.05.24 |
[따배씨] 7.6 소수 판단 예제 (0) | 2021.05.24 |
[따배씨] 7.4 다중선택 else if ~ 7.5 else 와 if 짝짓기 (0) | 2021.05.24 |
[따배씨] 7.2 표준 입출력 함수들 getchar(), putchar() ~ 7.3 ctype.h 문자 함수들 (0) | 2021.05.21 |
Comments