티스토리 뷰

C

[C++ Primer Plus] CH 3. Dealing with data

나야 2010. 1. 31. 16:26
3장부터는 좀 속도를 내기로 했습니다.

우선 정수 형식에 대한 코드입니다.
실행해보면,
1:2
2:4
3:8
4:16
5:32
6:64
7:128
8:256
9:512
10:1024
11:2048
12:4096
13:8192
14:16384
15:32768
16:65536
17:131072
18:262144
19:524288
20:1048576
21:2097152
22:4194304
23:8388608
24:16777216
25:33554432
26:67108864
27:134217728
28:268435456
29:536870912
30:1073741824
31:2147483648
32:4294967296
33:8589934592
34:17179869184
35:34359738368
36:68719476736
37:137438953472
38:274877906944
39:549755813888
40:1099511627776
41:2199023255552
42:4398046511104
43:8796093022208
44:17592186044416
45:35184372088832
46:70368744177664
47:140737488355328
48:281474976710656
49:562949953421312
50:1125899906842624
51:2251799813685248
52:4503599627370496
53:9007199254740992
54:18014398509481984
55:36028797018963968
56:72057594037927936
57:144115188075855872
58:288230376151711744
59:576460752303423488
60:1152921504606846976
61:2305843009213693952
62:4611686018427387904
63:9223372036854775808
64:0

Signed Integer Type
short values can be -32768~32767 (2 bytes)
int values can be -2147483648~2147483647 (4 bytes)
long values can be -9223372036854775808~9223372036854775807 (8 bytes)

Unsigned Integer Type
unsinged short value can be 0~65535 (2 bytes)
unsigned int value can be 0~4294967295 (4 bytes)
unsigned long value can be 0~18446744073709551615 (8 bytes)

Character Type
CHAR_BIT: 8 bits
char value can be -128~127 (1 bytes)
signed char value can be -128~127 (1 bytes)
unsinged char value can be 0~255 (1 bytes)

커널버전은 2.6.31 이라고 나오고, x86_64인데, 현재 64bit로 컴파일하고 있는지, 32bit로 컴파일하고 있는지도 모르겠습니다. 저는 beginner입니다.

에, 다음은 overflow에 대한 얘기가 쓰여 있는데, 빙글빙글 돌고도는군요

다음은 int와 char 에 대한 형변환 얘기도 있는데, cout이 입력되는 데이터의 형식에 따라 다르게 행동해서 알아두어야 할 필요도 있을 것 같습니다. 예를 들면, 10진수 65가 int에 들어 있으면, cout이 65를 출력하고, char에 들어있으면 A를 출력하는 식이죠.

변수이름에 \u로 escape한 unicode를 쓸 수 있다고 하는데, 일단 패스패스.

int와 char가 signed 인지 unsigned 인지는 구현에 따라 달라진다고 써있네요.

그 다음에, bool 형식에 대한 얘기가 나와있는데, 자바에서는 true는 true고, false는 false 일 뿐이었는데, c++에서는 bool  형식에  0을 할당하면 false가 할당되고, 0이 아닌 값을 할당하면 true가 할당되는, 또 int 형식 변수에 true를 할당하면 1값을 갖게 되고, false를 할당하면 0값을 갖게 되는... 좀더 복잡하게 프로그램을 짤 수 있게 되어있네요.

다음은 const Qualifier(수식어?)에 대한 얘기가 나오는데,  #define을 사용하는 대신 const를 사용하면 변수 형식을 지정할 수 있고, 제한된 범위 내에서 사용할 수 있는 등의 장점이 있다고 합니다~

이제 드디어 부동소수점이네요.

실행한 결과는~
The following are the minimum number of significant digits
FLT_DIG: 6
DBL_DIG: 15
LDBL_DIG: 18

The following are the number of bits used to represent the mantissa
FLT_MANT_DIG: 24
DBL_MANT_DIG: 53
LDBL_MANT_DIG: 64

The following are the maximum and minimum exponent values
FLT_MAX_10_EXP: 38
DBL_MAX_10_EXP: 308
LDBL_MAX_10_EXP: 4932
FLT_MIN_10_EXP: -37
DBL_MIN_10_EXP: -307
LDBL_MIN_10_EXP: -4931
floating point number에 대한 용어가 잘 기억이 안납니다. mantissa 가 뭘까요?
지금 Floating point 를 보니, 부동소수점 자체가 잘 기억이 안나므로 나중에 천천히 보도록 하고 일단 패스패스.

뒤에 Type Conversion 얘기가 나오는데,  Type Conversion 을 실제로 쓸 때 읽어보기로 하고 패스~

 Chapter 3. 는 너무 대충대충 넘어가네욥.

남은 내용...
CH4. Compound Types
CH5. Loops and Relational Expressions
CH6. Branching Statements and Logical Operators
CH7. Functions: C++'s Programming Modules
CH8. Adventures in Functions
CH9. Memory Models and Namespaces
CH10. Objects and Classes
CH11. Working with Classes
CH12. Classes and Dynamic Memory Allocation
CH13. Class Inheritance
CH14. Reusing Code in C++
CH15. Friends, Exceptions, and More
CH16. The string class and the Standard Template Library
CH17. Input, Output, and Files
+ floating point



이번 장의 영어

humidity
- These plants need heat and humidity to grow well (Naver 영어사전)

Constitution
Constitution and its relative frequency, or the number of available Elvis impersonators. (본문)
사실 본문 중에서 데이터의 예로 들고 있는 문장인데, 해석이 되지 않아서 다시 보니
the most common letter in the U.S. Constitution and its relative frequency,
라는 문장이네요.


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
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 29 30
글 보관함