Fundamental Data Types n char signed char unsigned
































- Slides: 32
Fundamental Data Types n char, signed char, unsigned char n n (signed) short (int), (signed) int, (signed) long (int) n n 부호있는 정수 unsigned short (int), unsigned long (int) n n 문자(character)를 저장 부호없는 정수 float, double, long double n 실수(부동(浮動)소수) 2
Character Type in C n char n n 1바이트 = 8비트 ‘A’ = 65 = 10000012 char tmpchr = ‘A’; tmpchr in memory 0 1 0 0 0 1 6
Word in Computers n 워드(Word) n n 컴퓨터가 한 번에 처리할 수 있는 비트의 크기 예) 32 -bit word 32 bits 001 10 10 000 01 CPU 7
signed and unsigned n unsigned 계열 n n (signed) int type의 변수가 가질 수 있는 값의 범위 n n n unsigned short unsigned (int) unsigned long -231, -231 + 1, . . . , -1, 0, 1, 2, . . . , 231 – 1 -2, 147, 483, 648 2, 147, 483, 647 unsigned (int) type의 경우 n n 0, 1, 2, 3, . . . , 232 – 1 0 4, 294, 967, 295 9
예제 프로그램 #include<stdio. h> int main(void) { -실행결과 2147483647 int price; unsigned uprice; -1 4294967295 uprice = 2147483647; -데이터 타입이 가질 수 있 는 최대값의 범위를 넘어가 는 값을 할당해도 컴파일 에러는 나지 않는다. printf(“%d %u”, price, uprice); uprice = 4294967295; printf(“n%d %u”, price, uprice); return 0; } 10
ASCII 코드와 char #include<stdio. h> - 실행결과 int main(void) A: 65 { B: 66 char alphabet; C: 67 for(alphabet = ‘A’; alphabet <= ‘Z’; alphabet++) . . . printf(“%c: %dn”, alphabet); Z: 90 return 0; } - char 변수 alphabet에 ‘A’를 할당하면 alphabet 변수에는 65의 이진수 값이 들어간다. - printf() 함수 안의 %c, %d는 단지 alphabet의 값을 출력하는 방법만 지정해 주는 것이다. 11
실수계열 Data Type n float, double, long double n n float: 4 bytes double: 8 bytes long double >= double 복잡한 실수의 계산은 정확하지 않다. n 간단한 경우에는 크게 문제가 되지 않는다. 12
sizeof 연산자(2/3) #include<stdio. h> int main(void) { printf(“The size of some fundamental types is computed. nn”); printf(“ char: %3 u byte n”, sizeof(char)); printf(“ short: %3 u bytes n”, sizeof(short)); printf(“ int: %3 u bytes n”, sizeof(int)); printf(“ long: %3 u bytes n”, sizeof(long)); printf(“ unsigned: %3 u bytes n”, sizeof(unsigned)); printf(“ float: %3 u bytes n”, sizeof(float)); printf(“ double: %3 u bytes n”, sizeof(double)); printf(“long double: %3 u bytes n”, sizeof(long double)); return 0; } 15
연산자(Operators) n 산술연산자(Arithmetic operators) n n 할당연산자(Assignment operators) n n +, -, *, /, %(나머지 연산자) =, +=, -=, *=, /=, %=, . . . 증감연산자(Increment and decrement operators) n ++, -20
% 연산자 예제 프로그램 #include<stdio. h> int main(void) { int i; for(i = 1; i <= 100; i++) { if(i % 17 == 0) printf(“%d is a multiple of 17. n”, i); } return 0; } 21
관계연산자 (Relational and Equality Operators) n Relational Operators n n <, >, <=, >= Equality Operators n ==(equal to), !=(not equal to) 24
Operator Association Rule 26
관계 수식의 값 예제 프로그램 #include<stdio. h> int main(void) { -실행결과 113 int a, b, c = 0; 0 a = ++c; 1 b = c++; printf(“%d %d %dn”, a, b, ++c); printf(“%dn”, a > 3); printf(“%dn”, a <= 3); return 0; } 30
할당수식의 값 예제 프로그램 #include<stdio. h> int main(void) { int i, j; -j = 0 수식의 값 : 0 -if의 조건식은 항상 0(False)이다. scanf(“%d”, &i); j = i % 2; if(j = 0) printf(“This number is even. n”); else printf(“This number is odd. n”); return 0; } 32
































