Beruflich Dokumente
Kultur Dokumente
Microsoft Windows
14' coot« Enter nall>!."; dn» name; 15: coot « 'EntI!r age : '; do »~; 1&: rout « "EnIIII degree: ': dn» deg!ee:
17: }
18: }; 19:
20: main(
211 { . If Create a historY
22' history person, /I Get da!J for hiStOry
nt·person,getDat3( );
24: sizeOI(peoool);
AUNG MYINT (M.E., AUSTRALIA)
CHAPTER 1 c++ BASICS
1.1. A Brief History of C and c++ 10
1.2. My First C++ Program 12
:'1.3. Identifiers 15
1.4. Keywords 16
1.5. Variables 17
1.6. Constants 24
1.7. Expressions 30
1.8. Assignments 31 CHAPTER 2 FUNCTIONS
2.1. Create a Simple Function 46
2.2. Pass the Variables by Value 50
2.3. Pass Variables by Reference 59
2.4.' Default Function Arguments 63
2.5. Inline Functions 65
2.6. Local and Global Variables 65
2.7. Overloaded Functions 69
2.8. Recursion 73
2.9. Passing Structure Variables 77 3.1. The if Statement 82
3.2. The goto Statement 86
3.3. The if-else Statement 92
3.4. Nested if Statement 96
3.5. The while Statement 101
3.6. The do-while Statement 108
3.7. The for Statement 114
3.8. Nested Loops 120
3.9. The switch Statement 123
3.10. The break Statement 127
3.11. The continue Statement 129 CHAPTER 3
PROGRAM FLOW CONTROL
CHAPTER 4
POINTERS AND ADDRESSES
4.1. Referencing Variables with Pointers 133
4.2. Pointers and Arrays 136
4.3. Pointers to Structures 140
4.4. Pointers as Function Arguments 142
4.5. Passing Arrays by Pointers 145
4.6. Pointers and Strings 151
4.7. Arrays of Pointers to Strings 156
4.8. Pointers to Pointers 158
4.9. Memory Allocation 164
4.10. Using Reference Variables 168 1979 y~S ~S2:y8:GC\Y.)a50) G'dG~qo)~§~GClY)84( I New Jersy §~cj>uS I AT & T Bell Laboratories 'PCI(8d?8Gcj>a? Bjarne Stroustrup ~~"6~~llO'Y.)o~ot>j~g)O)S2:0) C language d?G'dG§~[9: C++ ~a? object-oriented programming language O)Syd?Gtq:::>.Y.l:~olO)uSll G'dQ)0) C++ ~())05ol),):11 C with Classes 03G'd~~Go:~olO)uSll 1983 ~&SGQ'")a5~ C++ 03~>,)~~Gr,'''"'8:03a5
L IL La c:. 0 LJ "T J LoT c:. ljJ L
0'Y.)0111 C++ 0) C d?m;:D9~9ClY):a? version 01011 C++ source code G06d? C compiler G06GoT 'P
o c C Cf to'" t to. r,:' ceo C 0 C ' t 0
run ~CG8'd')C ron ~G? In erpre er O(G'd~:t:1l~o)o)G(\)1I O)Q)~l.O) ++ 0( 9.. superse ~
Gr,''''~olO)uSll C language g) (\)803QO'Y.)G'd0)~ru:GC\Y.)a5ci5 C++ g)(\)~: (\)803QO'Y.)c15:11 O)S~GO'Y.)
L:f..JU J L LO "I L T L L J c:. L LO "I L L 0
o C C leer,;. C , k d C I "l 0 ,"
~O)O) I ++ anguage 'PG'd::DQ)CX)0t1~ClY):G? eywor G06O) anguage 'P ~OI::>;(:~Go:>'{ G'd8
k doC ld tif ,. r,: 0 C "l ," 0 Coo
eywor G06o( program 'P I en I rer G06G'dGcj>f. G'd~:t:1l~t>jo)o)GO!" G'd8C1( program ~Jl:o(
C++ 0) compile (\)8(\3~Qol),):11 C compiler 0)0 compile (\)8~: run Go:~8g)01011 ~or,;.Sr,;.S
L Lo-l IL LtJ LJ ljlj
C , C I 0 0 [9 0 C C 0 C C '''l C "l
ty)~o)::DG'dG££ anguage m::DG£ :::>.Y.l:;:DQC ++ m;:Dm(\)mG(\)c\y')o)G'd~1 (\)O)mG~I')Gg)g)OIIl
IL T To L T L -L LOa 0 IL iJ - J
C++ Basics
0.0 A Brief History of C and C++
C language ciS Dennis Ritchies £::D m~0'ltO)')o~OQGg)O)S3:m AT & T Bell Lab g) Cl)0
L L IL 0 T iJ L -L C J L
ciSt(;,f,Qt: 1970 ;;lcSlSg) interpreted programming language B(PL ciS ~:~:GQ::::D'J:QO)')~SolO)oSll
l T 1. L J J L J tf "I 0 lj
c C C (' I I I 0 0 A bl I 0 -, C 0 C 0 '1' C C
~§w~mm '\1. ow- eve programming 0( ssem y anguage C\(0 C\(O~C<f,0IOIl ;nmq?w
s:i;:m Cl)dSt:G'd~:~l03 Cl)oSmcn high-level language ~;nrfJ::DoSO)')Jl:Go111 Ritchie c:fY) ::DCI)rfJg,
TC IL L L l:f LO 0 IL 0 To 0 iJ 0 IL JI
G'd::D:~lGscn UNIX system PDP-ll 0rfJ~')0 C d3(1)rfJGo) 0G:r::;::::i;GO)') GG'd')t~t::D'):olO)oSll
l l::1 T 0 J \.. 00 t:ju. (I L:j 0
~G'd;;l1,? UNIX developer §So? Ken Thompson mCl)~: UNIX system d2 C ~ G~b:DGq::::D'J:
O)oSGCI) II C ox: UNIX system '? ,SG'd~0:0)~~Gf~010)oSll
O)S~~g) AT & T mG£ UNIX system d3 O)m:8c0GO)g)G'd::D:~laG'dO)rfJ G'dCl)O)'):GCI)')rfJ
iJT J T l m l 0 j l tj LO 0
G G" (I 0 C C ,G c. I C ~c ''1 C
f:f:'\1.c\]llvG~ anguage ceo O)<J?~CI) Gmpc::::D'J:Go;?'\1. G'df:00~: anguage 0)0Y[jID~:VOlo)WII
wt:G'ddl:;nrfJm O)m:8c0Gmnt::::D'J:Go) Gmnt:mOOrfJ~:G'dCl)Oot:::D'J:cnG'd~I~g)GO)') high level
lJ m L i,J- 0 l,J- 0 L:::1 L 0 0 iJT J 0
language ,?0:?:Gfo? (OBOL ~. low level language ,?0:?:Gfo? Assembly language ~d2
o co, (' 0 C C 0 C~ '1 ,G 0 COt (P/M to
~O?o)o)::DCI)')O? '\1. O(mO(O)C\(mtlGo!" G'dGG'd~fm rrucrocompu er Go;?,? opera Ing
system mC}?~:~:GfaJ0111 high-level language G'dGf~G'd~:~.r:GfO)')m BASI( language §SolO)oSll 1979 ;;lcSlSg) Brian Kernighan £ Dennis Ritchie dSo:cnGQ::::D'J:cn The ( Programming
L J J To LO IL 0 "I 0
L COp to H II C 0 C c, '1 C '1 C, G C '1 C , (
anguage 0'J8f00( ren Ice a 0'J8f0O(mmGfO(O)GOvOIO)WII GIGO~O;> G'd30'J8f0,?010CO?
I 0fj to 0 t d dOC C 0 C '1 C , r,- v-v C "(I 0
anguage spec rca Ion Go;?O( s an ar or. ~::Do)~o)~CG::D:OI::1fi::1I G;;l0)00)'):'\1.GtI-,qqc assic
C" 0, 'T' '1 C 0 C G co, C C c[9 K&R (0 'T'
CDOG;;l1 Qg)GOIII 0)0;;l1l mCl):l>:G0'JG'dom 0'JGQ:::DGO)Q £')~:l>G'd01'):;nO)oo~) : CI) cot 0)')
LO -L J 0 iJLo c:. L L 'T IL 0 -LoT c.:. iJ 0 ~ LO
CO, 0 C 0 C OC o c IBM C 0 fCC 1981 C P(
CI)~:~q.1I O(mO(m~c~c mCl)~: main rame Go;?O(o)C\(OGfSP~ y,0,? GCI)')m
cO~08(1)')O)oSGCI)II IBM ~ora? IBM clone Go;?mCl)~:Go\~Go1Golll Microsoft ~oS~8m ~A.ooo~a?:G8'd')t§tCl)')o? Windows 30X operating system d2 ( language ~OGq:o?rfJo?G'd;;ll,?
( 0 C C C C c . C '1 G h ( I
CYcG'd~.r:m 0( ~0)~0)06J0)06J0) Cl)m;;l~:O)')~;nf:G~ol::1fi::1I 3G'dGt:JG'dGfGo;?c:fY) anguage
C C cr::;::: c~c '1 C
G'do;?m GqmfG'd::D9u,)G'd::D9[j0q?'):GIDOIO)WlI
1983 ;;lcSlSg) ANSI co C language definition ciS G'dQt::Da5~a5~: ISO (International
L J J l -l J l::j
Standards Organization) d3;nrfJCI)rfJO)t~Qmg) 1990 ;;l&Scnt~ C standard document d3~rfJ~O
L l::j 0 "T J l J -- -tl .J L L J
§~~~8~010)oSll ~~0'J8foOJ,) Standard ( 01011 international standard c++ document d2
1998 ;;lcSlSg)G'd~:::Da5ooa5GogtQo10)oSll 0'J0aS::DG'dGSS C I C++ dSQdS:O)ch SGoT 8 timeline
L J J t::J l L 0 It T T· 1..- -.., L JL
(++ Basics
00
C!<C\Y.): (:). :)) C and C+ + Timeline
Year Event
1970
1972
, UNIX system d5 minicomputer c;mooooo):c:gtG97.>t Assembly
-0 ~ L lj[L
language ~ Thompson roGE>f::D?:o'1m0511
C programming language d3 Dennis Ritchie m Q)mt38.8:C\J6~:
L L Ltj
Thompson m UNIX system d? C ~ oo::x>S[9tGE>[:olm05n
~ie .~.' ,Se;Q)6o;r<;;E>f::D?:o? C Programming Language 4)?~o? Prentice Hall m§05,6fi~~olm05n
1979
1983
1985
C language d? OOG§~[§: Bjarne Stroustrup m C with Classes (1st version) d? OOa:)9~9GE>[:::D?:olm05n
CP/M 8080 microcomputer operating system Go;?<p oo~:[9l ~td) C compiler"' Gin Q)mtroaS&c"\Y~61m05jl
1. • -0 0 jf"'--
C with Classes 1'')g~d? C++ 6?, OOg~G[9-:>S:c\)olm05n C d? standardize C\J88oomaS ANSI mG£Q)mSQ):::S:Go:olm05n
L LO 0 T c..:..
C++ d3r:Sooooo~:r:lgSG97.>t Cfront interpreter d3 AT&T mGS
Ltf J L L::f L L T
§~~Go:olm0511 Stroustrup GE>f::x>':l:o? The C++ Programming
Language 4)?Of8C\J~:'1?aS~C\J')olm0511 3~t<p MS-DOS platform ooooo):r:l~8o') C compiler GmC\J~:GoT C\J')oll:t, Ii
JL t1: L 0 .• 0 c r:J.
:):)
C++ Basics
1986
Cfront dS MS-DOS '=l')ootGo:o1oooSll MS-DOS C compiler ooSddS
L J L L
M" ft cs 0,,., C'
ICroSO mGtL:"f.~~OIOO(l)1I
1998
1989
c standard ~ ANSI o:>Gt <;>~O<:JXi.)GO~~Io::>ci)11 Borland mG; C++ compHer (for MS-OOS) ~(.)1oouSH
1991
Microsoft mGt C compiler (for MS-DOS) d? §~~o1oooSll
o. J My First C++ Program
. ( ) ~ 'E 101 0 C' C' C' 0 C' 0 C' , C
« o, 0 if-iG(l), l:j0)'):0? X .cpp program ()')')~E>[c O6ltGO')')0?,0oocGE>[=0(mO? ++
,." C' 0,., C'
program OOG:::D:Gru:OIOIl program c» G:::D:G061O;> run OGE>[0IOO(l)1I
011
c++ Basics
OJ