2. 개 ¶
- 결과 로 15~16/ 16~17
- High-level programming skill보단 low-level HW 구를 명 low-level 근는 독(...) 딩
- 고 료: 봉 교님 료: http://cau.ac.kr/~bongbong/c10/
2.1. 1(2012 - 03 - 27) ¶
-
- C를 low-level 관부 근기 노만 부
- C는 UNIX 개발 목로 만들 기 때문 OS 기가 되는 기 가 다고 단
- 개념나 scanf &가 는 러가 keyword 대 명기
- binary digit를 롯 기 개념 또 명
- C는 UNIX 개발 목로 만들 기 때문 OS 기가 되는 기 가 다고 단
- 드를 가며, Compile error, logical error, debug error 개념 대 명
- 로그래밍 러 대방법 부 명
- 로그래밍 러 대방법 부 명
- C 명
- variable 및 main function 명
- #include가 무 header file 무 명
- 러 과 compile -> link -> build 과 명
2.1.1. 과: 목 늘 배 내 리. ¶
- c
- High-Level 과 Low-Level 모두 고 다
- High-Level 가까록 람 기 다 (Human Friendly)
- High-Level 가까록 람 기 다 (Human Friendly)
- Low-Level 가까록 기가 기 다 (Machine Friendly)
- High-Level 과 Low-Level 모두 고 다
- High-Level 를 Low-Level 로 변는 다
- 되는 모든 되는 범 구
- , 메모리, 력로 구
- , 메모리, 력로 구
- bit
- 법로 나낼 는 릿를 나낸다
- 1bit=0,1 / 2bit=00,01,10,11 / 3bit=000,001,010,011,100 ...
- 1bit=0,1 / 2bit=00,01,10,11 / 3bit=000,001,010,011,100 ...
- (Function) 들
- 미 는 를 가다 려 때 더 러 다
- 미 는 를 가다 려 때 더 러 다
- 변 (variable)
- int, float, char
- int는 를 나내고 때 며 력 %d를
- float는 래 까 고 때 며 력 %f를
- char는 문를 나내고 때 며 력 %c를
- int는 를 나내고 때 며 력 %d를
- int: integer type, 4 bytes
- char: It used to express a character, but also used to express a integer. 1 byte
- float: 4 byte, floating type number. Specification in IEEE 754-2008
- function: input -> output
- Main function
- real part of program
- It has start and end point of a program.
- return 0; : 0 is a flag noticing OS that program is ended.
- real part of program
2.2. 2(2012 - 04 -05) ¶
- 내: Variables, Data Types, Standard I/O
- Variables
- identifier -> 기 규 다.
- keyword
- overflow
- escape sequence
- identifier -> 기 규 다.
- Data Type
- Integer type: int(4 bytes), char(1 byte, be often used to express a character)
- float type: float, double (double is more correct than float)
- unsigned - MSB를 2배 를 더 많 나낼 다는 개념 명
- Maximum, minimum value of int(경 )
- Integer type: int(4 bytes), char(1 byte, be often used to express a character)
- Standard I/O
- format specifications
- printf, scanf
- scanf & 까?
- format specifications
- preprocessor(리기)
- #define
- #define
- automatic type conversion
- Example Problem: Write a program that converts meter-type height into feet(integer),inch(float)-type height. Your program should get one float typed height value as an input and prints integer typed feet value and the rest of the height is represented as inch type. (1m=3.2808ft=39.37inch) (: 봉 교님 ppt)
- Variables
2.2.1. 과 ¶
- 배 내 리
- 2법, 명, 단논법 공부기
- 늘 못 다 기
- 고1 과 대로 공부보기
- 변 반드 문나 underscore (_) 로 다
- 변 대문를 구다
- 러 미 는 (identifier)
- 변 로 다
- C 는 29 개 드가
- 변 는 값보다 더 값 되 때 발다
- 2법로 가 리되는 과 발 (?)
- 력 것과 다른 값 겨나게 된다
- 기능 기 림로 \ (back slash) 로
- 바 (\n), (\t), 따 (\"), 따 (\'), 래 (\\) .
- int : 4 byte. 를 . 래로는 린다
- char: 1 byte. 글를 (character).
- float, double: 4 byte, 8 byte. 를 므로 래 까 나낼 다
- double float보다 더 게 를 다
- float => -1.0E+38 ~ 1.0E+38 / double => -1.0E+308 ~ 1.0E+308
- 1.0E?
- double float보다 더 게 를 다
- unsigned ~ : 부만 로 더 범 를 나낼 만 를 다
- 를 법로 /를 구기 되는 맨 리 0 를 는 데 두 배 많 를
- 를 법로 /를 구기 되는 맨 리 0 를 는 데 두 배 많 를
- 2^31-1=???
- 기본 력 (Input) / 력 (Output)
- 더 <stdio.h>
- printf ("내", argument);
- scanf("format specifier(s)", &argument);
- format specifications
- 배 것 - %d (int), %f (float), %c (char)
- 배 것 - %d (int), %f (float), %c (char)
- scanf & : 력는 값 &뒤 변 기 메모리 는 변 를 리는 다
- #define 로
- 는 문 값 두고 다
#include <stdafx.h> #include <stdio.h> int main () { float meter=0; scanf("%f",&meter); int feet=meter*3.2808; float inch=(((meter*3.2808)-feet)/3.2808)*39.37; printf("%d feet %f inch\n",feet,inch); return 0; }
2.3. 3 (2012 - 04 -09) ¶
- Operators
- arithmetic operators: binary, unary
- priority
- precedence
- arithmetic operators: binary, unary
- assignment operator
- decrements / increments : postfix / prefix
-
- bitwise operator
- Binary numeral system
- Binary numeral system
- 2's complement: 방법
#include<stdio.h> int main() { int input, output; scanf("%d", &input); output = ~input; output ++; printf("%d\n", output); return 0; }
2.3.1. 과 ¶
- 당, 늘 배 내 리(로 ?)
- 를 력고 and operator를 그 보다 가 를 력라(scanf, printf )
- shift operator를 128(=2^5) 력고, 128 변(variable) 그 변 left shift operator를 32를 력라
- 다 값 라
- 1110 0111 ^ 1101 0001 = ?
- 1110 0111 | 1101 0001 = ?
- 1110 0111 ^ 1101 0001 = ?
- Assignment operator
- Equal sign (=) Assignment operator 를 나낸다
- 변게 값 기 된다
- : 른 ->
- Equal sign (=) Assignment operator 를 나낸다
- Decrement / Increment : postfix / prefix
- Decrement는 --로, Increment는 ++로 나낸다
- 감값 1
- Postfix 경 변 뒤 Decrement/Increment operator를 며 다른 끝난 된다
- Prefix 경 변 Decrement/Increment operator를 며 다른 기 된다
- Decrement는 --로, Increment는 ++로 나낸다
- (Shorthand Operators)
- 과 같 변가 되 경 를 다
- +=, -=, *=, /=, %=
- Ex. (A = A + B)는 (A += B ) 로 가능
- Ex. (A = A + B)는 (A += B ) 로 가능
- 과 같 변가 되 경 를 다
- (Bitwise Operators)
- 2법로 되는 Bit를
- 2법 (Binary numeral system)
- 1과 0만 를 나내는 방법.
- 2법 1 true, 0 false로 나나는 경가 다
- 2를 10로 바꾸려면 2 릿 따라 2^(n-1) 면 된다
- 10를 2로 바꾸려면 10를 2로 나 나머가 다면 1, 다면 0 면 된다
- 2법 (Binary numeral system)
- Left shift : a<
- a 모든 를 로 n 기며, 로 겨난 는 0 된다
- a 모든 를 로 n 기며, 로 겨난 는 0 된다
- Right shift : a>>n
- a 모든 를 른로 n 기며, 로 겨난 는 0 된다
- a 모든 를 른로 n 기며, 로 겨난 는 0 된다
- And : a & b
- a b 를 교 로 다르면 0, 로 같다면 1로 다
- a b 를 교 로 다르면 0, 로 같다면 1로 다
- Or : a | b
- a b 를 교 나라 1라면 1로 다
- a b 를 교 나라 1라면 1로 다
- XOR : a ^ b
- a b 를 교 로 다르다면 1, 로 같다면 0로 다
- a b 를 교 로 다르다면 1, 로 같다면 0로 다
- 1's complement : ~a
- a 를 모두 반다 : 1->0, 0->1
- a 를 모두 반다 : 1->0, 0->1
- 2법로 되는 Bit를
- 2's complement
- Bit 로 를
- A를 -A로 나내려면, A 를 1's complement로 반 1 더면 된다
- A를 -A로 나내려면, A 를 1's complement로 반 1 더면 된다
- Bit 로 를
#include <stdio.h> int main () { int num ; int temp1 ; printf ("enter a number : "); scanf ("%d", &num); temp1 = num & 1 ; if (temp1 == 1) { printf ("%d\n", num - 1); } else if (temp1 == 0) { printf ("%d\n", num - 2); } return 0; }
#include <stdio.h> int main () { int num = 1 ; num = num<<7; printf ("%d\n", num); int num2 ; num2 = num ; num2 = num2>>2; printf ("%d\n", num2); return 0; }
- 1110 0111 ^ 1101 0001 = 0011 0110
- 1110 0111 | 1101 0001 = 1111 0111