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
- 따배씨
- udemy
- greedy
- BFS
- 백준
- 인프런
- Python
- Cleancode
- BASIC
- Algospot
- 따라하며 배우는 C언어
- dfs
- Algorithm
- DP
- sorting
- C언어
- Math
- web
- JavaScript
- 종만북
- String
- programmers
- server
- BOJ
- php
- graph
- 정수론
- 따라하면서 배우는 C언어
- C
- 생활코딩
Archives
- Today
- Total
몽상실현개발주의
[따배씨] 6.5 사실과 거짓 ~ 6.6 _Bool 자료형 본문
따배씨 - 따라하며 배우는 C언어
6강 반복문
6.5 사실과 거짓 True and False
#include <stdio.h>
int main()
{
int tv, fv;
tv = (1 < 2);
fv = (1 > 2);
printf("True is %d\n", tv);
// True is 1
printf("False is %d\n", fv);
// False is 0
return 0;
}
#include <stdio.h>
int main()
{
int i = -5;
while (i)
printf("%d is true\n", i++);
// -5 is true
// -4 is true
// -3 is true
// -2 is true
// -1 is true
printf("%d is flase\n", i);
// 0 is flase
return 0;
}
- 0 == false, 0 != true
6.6 _Bool 자료형
- 고전적인 C 언어에서는 정수형을 이용하여 True/False 를 다루었음
- _Bool 자료형은 새로 추가됨
- 기존의 코드들과의 호환성을 위하여 _Bool 자료형으로 표기
#include <stdio.h>
int main()
{
_Bool boolean_true = (2 > 1);
_Bool boolean_false = (1 > 2);
printf("True is %d \n", boolean_true);
// True is 1
printf("False is %d \n", boolean_false);
// Flase is 0
printf(boolean_true ? "true" : "false");
// true
printf("\n");
printf(boolean_false ? "true" : "false");
// flase
return 0;
}
- printf(조건 ? True : False) - 삼항연산자
#include <stdio.h>
#include <stdbool.h>
int main()
{
bool bt = true;
bool bf = false;
printf("True is %d\n", bt);
// True is 1
printf("False is %d\n", bf);
// False is 0
return 0;
}
- stdbool.h
- #define bool _Bool
- #define true 1
- #define false 0
이 글의 모든 사진과 내용의 출처는 홍정모 교수님께 있음을 알려드립니다.
http://blog.naver.com/atelierjpro
http://www.inflearn.com/course/following-c
'Language > C' 카테고리의 다른 글
[따배씨] 6.10 다양한 대입 연산자들 ~ 6.11 콤마 연산자 (0) | 2021.05.20 |
---|---|
[따배씨] 6.7 관계연산자 우선순위 ~ 6.9 for 문의 유연한 사용 (0) | 2021.05.20 |
[따배씨] 6.4 관계 연산자 (0) | 2021.05.19 |
[따배씨] 6.2 의사 코드 ~ 6.3 진입조건 루프 (0) | 2021.05.19 |
[따배씨] 6.1 while 반복 루프에서 scanf()의 반환값 사용하기 (0) | 2021.05.19 |
Comments