7.1 분기문 if
If는 괄호안의 expression이 True면 Statement를 실행한다.
7.2 표준 입출력 함수들 getchar(), putchar() 예제
getchar()과 putchar()은 <stdio.h>에 들어있음.
이름대로 getchar()는 문자하나를 가져옴 (int형으로), putchar()는 (int형을 받아)문자하나를 출력함.
그런데 여러개문자를 입력하고 여러개 문자를 출력가능한데 이에 대한 부분은 이후 버퍼를 설명하는 부분에서 더 알수 있다.
조건문에 &&를 써서 and로 쓸수 있다.
문자는 아스키키코드에 대응되기 때문에 사칙연산 가능함.
7.3 <ctype.h> 문자 함수들
www.tutorialspoint.com/c_standard_library/ctype_h.htm
C Library - - Tutorialspoint
C Library - The ctype.h header file of the C Standard Library declares several functions that are useful for testing and mapping characters. All the functions accepts int as a parameter, whose value must be EOF or representable as an unsigned char. All the
www.tutorialspoint.com
7.5 else와 if 짝짓기
파이썬과 다르게 c는 줄바꿈, 인덴팅을 한다고 해도 컴파일러가 무시한다. 따라서 if와 else를 짝지을 때는 {} 로 영역 구분을 명확히 해주는것이 좋다.
7.7 논리 연산자 Logical operators
&& : and
|| : or
! : not (! 는 단항연산자임에 주의)
이하의 예시 참조
#include <iso646.h>를 사용하면 논리 연산자를 and, or, not을 써서 사용가능
우선순위는 이하의 링크 참조
en.cppreference.com/w/c/language/operator_precedence
C Operator Precedence - cppreference.com
The following table lists the precedence and associativity of C operators. Operators are listed top to bottom, in descending precedence. Precedence Operator Description Associativity 1 ++ -- Suffix/postfix increment and decrement Left-to-right () Function
en.cppreference.com
Short-circuit Evaluation
- 논리 연산자는 왼쪽껄로 True False가 판별 가능하면 오른쪽거는 실행시키지 않음
- &&와 || 는 sequence point로 작동함.
C는 파이썬에서 하던것 처럼 i >= 10 and i <= 20 를 10 <= i <= 20 로 작성 할수 없다. 문법적으로는 맞지만 문맥상으로 오류가 발생함.
7.9 조건 연산자
변수에 대입하는값을 조건에 따라 바꾸고 싶을때 사용
사용법은 이하의 예시 참조
7.10 루프 도우미 continue와 break
continue를 만나면 continue 이하의 부분은 실행하지않고 그 다음 루프로 넘어간다.
continue를 만나면 전체 루프를 끝내버린다.
continue는 placeholder로 사용할 수 있다.
(=파이썬의 pass와 비슷하게 사용가능하다는 것)
다중 반복문에서 break는 자기가 포함된 루프만 중단시킨다.
7.12 다중 선택 switch와 break
강의에서의 설명이 빈약하다 이하의 링크 참조
www.programiz.com/c-programming/c-switch-case-statement
switch...case in C Programming
C switch Statement In this tutorial, you will learn to create the switch statement in C programming with the help of an example. The switch statement allows us to execute one code block among many alternatives. You can do the same thing with the if...else.
www.programiz.com
'TIL > 따배씨' 카테고리의 다른 글
함수 (2021-01-13 ~ 2021-01-14) (0) | 2021.01.13 |
---|---|
문자 입출력과 입력 유효성 검증 (2021-01-12) (0) | 2021.01.12 |
반복문(2021-01-08 ~ 2021-01-09) (0) | 2021.01.08 |
연산자, 표현식, 문장 (2021-01-07) (0) | 2021.01.07 |
문자열과 형식 맞춘 입출력 (2021-01-05) (0) | 2021.01.05 |
댓글