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