1信息工程學(xué)院計(jì)算機(jī)技術(shù)教研室_第1頁(yè)
1信息工程學(xué)院計(jì)算機(jī)技術(shù)教研室_第2頁(yè)
1信息工程學(xué)院計(jì)算機(jī)技術(shù)教研室_第3頁(yè)
1信息工程學(xué)院計(jì)算機(jī)技術(shù)教研室_第4頁(yè)
1信息工程學(xué)院計(jì)算機(jī)技術(shù)教研室_第5頁(yè)
已閱讀5頁(yè),還剩84頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、概述 C+是一門混合型面向?qū)ο蟪绦蛟O(shè)計(jì)語(yǔ)言,它兼容了C語(yǔ)言并彌補(bǔ)了其缺陷,增加了面身對(duì)象的能力。其中,改造后的C語(yǔ)言是面向?qū)ο蟛糠值幕A(chǔ)。一般語(yǔ)法的改進(jìn)指針和引用函數(shù)的改進(jìn)類和對(duì)象構(gòu)造函數(shù)和析構(gòu)函數(shù)2.1 C+程序的開發(fā)過程 C+語(yǔ)言是一種高級(jí)程序設(shè)計(jì)語(yǔ)言,它的開發(fā)過程與其他高級(jí)語(yǔ)言程序開發(fā)過程類似,一般要經(jīng)過四個(gè)步驟: 執(zhí)行編輯編譯鏈接編輯是指把按照C+語(yǔ)法規(guī)則編寫的程序代碼通過編輯器(Borland C+, Visual C+, Turbo C+ 等)輸入計(jì)算機(jī),并存盤。在存盤時(shí),C+源文件的擴(kuò)展名為.CPP。編譯將編輯好的C+源程序通過編譯器轉(zhuǎn)換為目標(biāo)文件(OBJ文件)。即生成該源文件的

2、目標(biāo)代碼。2.1 C+程序的開發(fā)過程鏈接將用戶程序生成的多個(gè)目標(biāo)代碼文件(.obj)和系統(tǒng)提供的庫(kù)文件(.lib)中的某些代碼連接在一起,生成一個(gè)可執(zhí)行文件(.exe)。執(zhí)行把生成的可執(zhí)行文件運(yùn)行,在屏幕上顯示運(yùn)行結(jié)果。用戶可以根據(jù)運(yùn)行結(jié)果來判斷程序是否出錯(cuò)。2.1 C+程序的開發(fā)過程2.1 C+程序的開發(fā)過程書寫格式C+語(yǔ)言程序的書寫格式自由度高,靈活性強(qiáng),隨意性大,如一行內(nèi)可寫一條語(yǔ)句,也可寫幾條語(yǔ)句;一個(gè)語(yǔ)句也可分寫在多行內(nèi)。不過應(yīng)采用適當(dāng)?shù)母袷綍鴮?,便于人們閱讀和理解。為了增加程序的可讀性和利于理解,編寫程序時(shí)按如下要點(diǎn)書寫:(1)一般情況下每個(gè)語(yǔ)句占用一行。(2)不同結(jié)構(gòu)層次的語(yǔ)句,

3、從不同的起始位置開始,即在同一結(jié)構(gòu)層次中的語(yǔ)句,縮進(jìn)同樣的字?jǐn)?shù)。(3)表示結(jié)構(gòu)層次的大括弧,寫在該結(jié)構(gòu)化語(yǔ)句第一個(gè)字母的下方,與結(jié)構(gòu)化語(yǔ)句對(duì)齊,并占用一行。(4)適當(dāng)加些空格和空行。2.1 C+程序的開發(fā)過程C+語(yǔ)言程序由以下基本部分組成。1. 函數(shù)一個(gè)C+程序是由若干個(gè)函數(shù)構(gòu)成的。函數(shù)分為庫(kù)函數(shù)(標(biāo)準(zhǔn)函數(shù))和自定義函數(shù)。庫(kù)函數(shù)一般是由系統(tǒng)提供的。一個(gè)完整的C+語(yǔ)言程序只有一個(gè)主函數(shù)。2. 預(yù)處理命令預(yù)處理命令以位于行首的符號(hào)“#”開始,C+提供的預(yù)處理有宏定義命令、文件包含命令和條件編譯命令三種。 2.1 C+程序的開發(fā)過程3. 程序語(yǔ)句 一條完整的語(yǔ)句必須以分號(hào)“;”結(jié)束。程序語(yǔ)句有如下幾

4、類:(1)說明語(yǔ)句用來說明變量的類型和初值。如下面語(yǔ)句是把變量說明為浮點(diǎn)數(shù)。float a, b, c;又如下面語(yǔ)句是把變量sum說明為整型變量,并賦初值為零。int sum = 0;2.1 C+程序的開發(fā)過程(2)表達(dá)式語(yǔ)句由一個(gè)表達(dá)式構(gòu)成一個(gè)語(yǔ)句,用以描述算術(shù)運(yùn)算、邏輯運(yùn)算、或產(chǎn)生某種特定動(dòng)作,在任何表達(dá)式最后加一個(gè)分號(hào)就構(gòu)成了一個(gè)語(yǔ)句。如下例由賦值表達(dá)式加“;”就構(gòu)成一個(gè)賦值表達(dá)式語(yǔ)句。(3)程序控制語(yǔ)句用來描述語(yǔ)句的執(zhí)行條件與執(zhí)行順序的語(yǔ)句,C+語(yǔ)言的控制語(yǔ)句有9種,如下頁(yè)所示。其語(yǔ)句中的括號(hào)( )表示其中是條件,表示內(nèi)嵌的語(yǔ)句。 2.1 C+程序的開發(fā)過程if () else條件語(yǔ)句

5、for () 循環(huán)語(yǔ)句while () 循環(huán)語(yǔ)句do while ()循環(huán)語(yǔ)句continue結(jié)束本次循環(huán)語(yǔ)句break中止循環(huán)式(switch語(yǔ)句)switch多分支選擇語(yǔ)句goto轉(zhuǎn)移語(yǔ)句return從函數(shù)返回語(yǔ)句2.1 C+程序的開發(fā)過程(4)復(fù)合語(yǔ)句復(fù)合語(yǔ)句是一種十分重要的語(yǔ)句,由大括號(hào)和把一些說明和語(yǔ)句組合在一起,使它們?cè)谡Z(yǔ)法上等價(jià)于一個(gè)簡(jiǎn)單語(yǔ)句;可由若干簡(jiǎn)單語(yǔ)句或復(fù)合語(yǔ)句組成。例如:if ( ab ) c = a - b; d = c * a; else c = a + b; d = c * b; 2.1 C+程序的開發(fā)過程C的輸入和輸出CC+2.2 一般語(yǔ)法的改進(jìn)注釋2.2 一般

6、語(yǔ)法的改進(jìn)變量初始化 C+支持兩種形式的初始化第一種形式是使用賦值操作符的顯式語(yǔ)法形式 int ival = 1024; string project = Fantasia 2000;在隱式形式中初始值被放在圓括號(hào)中 int ival( 1024 ); string project( Fantasia 2001 ); 在這兩種情況中ival 都被初始化為1024 而project 的初始值為Fantasia 20002.2 一般語(yǔ)法的改進(jìn)變量定義可以位于程序中的任何地方2.2 一般語(yǔ)法的改進(jìn)符號(hào)常量的定義CC+2.2 一般語(yǔ)法的改進(jìn)強(qiáng)制轉(zhuǎn)換類型C的強(qiáng)制類型轉(zhuǎn)換法 (類型名)表達(dá)式函數(shù)表示法(僅

7、限簡(jiǎn)單類型) 類型名(表達(dá)式) int i=int(1.35); 2.2 一般語(yǔ)法的改進(jìn)結(jié)構(gòu)體與枚舉類型的用戶標(biāo)識(shí)名enum traffic red,green,yellow;struct student int num; char name20;traffic Light;student stu1; !不必在一個(gè)結(jié)構(gòu)體名之前加struct,不用在一個(gè)枚舉類型名之前加關(guān)鍵字enum。2.2 一般語(yǔ)法的改進(jìn) C+ has a set of fundamental types corresponding to the most common basic storage units of a com

8、puter and the most common ways of using them to hold data: A Boolean type (bool )Character types (such as char )Integer types (such as int )Floating point types (such as float )Bjarne Stroustrup AT&T Labs2.3 數(shù)據(jù)類型和表達(dá)式In addition, a user can define Enumeration types for representing specific sets of v

9、alues (enum )There also is a type, void , used to signify the absence of informationBjarne Stroustrup AT&T Labs2.3 數(shù)據(jù)類型和表達(dá)式From these types, we can construct other types:Pointer types (such as int *)Array types (such as char )Reference types (such as double &)Data structures and classesBjarne Strous

10、trup AT&T Labs For most applications, one could simply use bool for logical values, char for characters, int for integer values, and double for floating point values. The remaining fundamental types are variations for optimizations and special needs that are best ignored until such needs arise.2.3 數(shù)

11、據(jù)類型和表達(dá)式 Specifiers modify the meanings of the basic built-in types and expand them to a much larger set. There are four specifiers: long, short, signed, and unsigned. long and short modify the maximum and minimum values that a data type will hold. A plain int must be at least the size of a short. Th

12、e size hierarchy for integral types is: short int, int, long int. The size hierarchy for floating point numbers is: float, double, and long double. “Long float” is not a legal type. There are no short floating-pointSpecifiersThinking in C+2.3 數(shù)據(jù)類型和表達(dá)式 The signed and unsigned specifiers tell the comp

13、iler how to use the sign bit with integral types and characters (floating-point numbers always contain a sign). An unsigned number does not keep track of the sign and thus has an extra bit available, so it can store positive numbers twice as large as the positive numbers that can be stored in a sign

14、ed number. signed is the default and is only necessary with char; char may or may not default to signed. By specifying signed char, you force the sign bit to be used. SpecifiersThinking in C+2.3 數(shù)據(jù)類型和表達(dá)式指針也是一種變量,指針變量專門用來存放其它數(shù)據(jù)在內(nèi)存的地址。是一種間接訪問變量或?qū)ο蟮姆椒āR檬悄硞€(gè)變量或?qū)ο蟮膭e名,是另一種訪問變量或?qū)ο蟮姆椒ā?* ;& =;指針和引用(Pointer&

15、Reference) 2.3 數(shù)據(jù)類型和表達(dá)式引用類型的概念(Reference) 引用是指給對(duì)象的地址取個(gè)別名,對(duì)引用的改動(dòng)則是對(duì)目標(biāo)的改動(dòng)。 int int1; int &rint=int1;引用不是值,不占有存儲(chǔ)空間引用必須初始化,并且不再指向其他不同的變量2.3 數(shù)據(jù)類型和表達(dá)式引用類型的概念(Reference) int ival = 1024;/ ok: refVal is a reference to ivalint &refVal = ival;/ error: a reference must be /initialized to an objectint &refVal2;

16、2.3 數(shù)據(jù)類型和表達(dá)式引用類型的概念(Reference) int ival = 1024;int &refVal = ival;int min_val = 0;/ ival is set to the value of refVal / refVal is not set to refer to min_valrefVal = min_val; Once defined, a reference cannot be made to refer to another object (this is why it must be initialized).C+ Primer2.3 數(shù)據(jù)類型和表

17、達(dá)式引用類型的概念(Reference) int ival = 1024;int &refVal = ival;refVal += 2; All operations on the reference are actually applied to the object to which the reference refers, including the address-of operator. For example:C+ Primeradds 2 to ival, the object referred to by refVal. 2.3 數(shù)據(jù)類型和表達(dá)式引用類型的概念(Referen

18、ce) int ival = 1024;/ ok: refVal is a reference to ival int &refVal = ival;/adds 2 to ival refVal += 2;/assigns ii the value currently associated with ival int ii = refVal;/initializes pi with the address of *pi = &refVal; All operations on the reference are actually applied to the object t

19、o which the reference refers, including the address-of operator. For example:C+ Primer2.3 數(shù)據(jù)類型和表達(dá)式動(dòng)態(tài)內(nèi)存分配(Dynamic memory allocation)靜態(tài)與動(dòng)態(tài)內(nèi)存分配的兩個(gè)主要區(qū)別是 靜態(tài)對(duì)象是有名字的變量,直接對(duì)其進(jìn)行操作。而動(dòng)態(tài)對(duì)象是沒有名字的變量,通過指針間接地對(duì)它進(jìn)行操作。靜態(tài)對(duì)象的分配與釋放由編譯器自動(dòng)處理,程序員需要理解這一點(diǎn),但不需要做任何事情。相反,動(dòng)態(tài)對(duì)象的分配與釋放必須由程序員顯式地管理,相對(duì)來說比較容易出錯(cuò)它通過new 和delete 兩個(gè)運(yùn)算符來完成。2.4

20、 動(dòng)態(tài)內(nèi)存分配動(dòng)態(tài)內(nèi)存分配(Dynamic memory allocation)malloc()和free(). CC+2.4 動(dòng)態(tài)內(nèi)存分配 new 運(yùn)算符動(dòng)態(tài)分配堆內(nèi)存 使用形式:指針變量 = new 類型 (常量); 指針變量 = new 類型 表達(dá)式 ; 作用:從堆分配一塊“類型”大小的存儲(chǔ)空間,返回首地址 其中:“常量”是初始化值,可缺省 創(chuàng)建數(shù)組對(duì)象時(shí),不能為對(duì)象指定初始值 delete 運(yùn)算符釋放已分配的內(nèi)存空間 使用形式:delete 指針變量 ;delete 指針變量 ; 其中:“指針變量”必須是一個(gè) new 返回的指針2.4.1 new和delete操作符int * p1 =

21、 new int ;char * p2 = new char ;float * p3 = new float ;int * p4 = new int 4 ; delete p1 ;delete p2 ;delete p3 ;delete p4 ;2.4.1 new和delete操作符int * p1 = new int ;char * p2 = new char ;float * p3 = new float ;int * p4 = new int 4 ; delete p1 ;delete p2 ;delete p3 ;delete p4 ;p12.4.1 new和delete操作符int

22、* p1 = new int ;char * p2 = new char ;float * p3 = new float ;int * p4 = new int 4 ; delete p1 ;delete p2 ;delete p3 ;delete p4 ;p1p22.4.1 new和delete操作符int * p1 = new int ;char * p2 = new char ;float * p3 = new float ;int * p4 = new int 4 ; delete p1 ;delete p2 ;delete p3 ;delete p4 ;p1p2p34.5.1 new

23、 和 delete 操作符2.4.1 new和delete操作符int * p1 = new int ;char * p2 = new char ;float * p3 = new float ;int * p4 = new int 4 ; delete p1 ;delete p2 ;delete p3 ;delete p4 ;p1p2p3p44.5.1 new 和 delete 操作符2.4.1 new和delete操作符int * p1 = new int ;char * p2 = new char ;float * p3 = new float ;int * p4 = new int 4

24、 ; delete p1 ;delete p2 ;delete p3 ;delete p4 ;p2p3p4p14.5.1 new 和 delete 操作符2.4.1 new和delete操作符int * p1 = new int ;char * p2 = new char ;float * p3 = new float ;int * p4 = new int 4 ; delete p1 ;delete p2 ;delete p3 ;delete p4 ;p2p3p4p14.5.1 new 和 delete 操作符2.4.1 new和delete操作符int * p1 = new int ;ch

25、ar * p2 = new char ;float * p3 = new float ;int * p4 = new int 4 ; delete p1 ;delete p2 ;delete p3 ;delete p4 ;p2p3p4p14.5.1 new 和 delete 操作符2.4.1 new和delete操作符int * p1 = new int ;char * p2 = new char ;float * p3 = new float ;int * p4 = new int 4 ; delete p1 ;delete p2 ;delete p3 ;delete p4 ;p3p4p2p

26、12.4.1 new和delete操作符int * p1 = new int ;char * p2 = new char ;float * p3 = new float ;int * p4 = new int 4 ; delete p1 ;delete p2 ;delete p3 ;delete p4 ;p3p4p2p12.4.1 new和delete操作符int * p1 = new int ;char * p2 = new char ;float * p3 = new float ;int * p4 = new int 4 ; delete p1 ;delete p2 ;delete p3

27、 ;delete p4 ;p4p2p1p32.4.1 new和delete操作符int * p1 = new int ;char * p2 = new char ;float * p3 = new float ;int * p4 = new int 4 ; delete p1 ;delete p2 ;delete p3 ;delete p4 ;p4p2p1p32.4.1 new和delete操作符int * p1 = new int ;char * p2 = new char ;float * p3 = new float ;int * p4 = new int 4 ; delete p1 ;

28、delete p2 ;delete p3 ;delete p4 ;p2p1p3p42.4.1 new和delete操作符int * p1 = new int ;char * p2 = new char ;float * p3 = new float ;int * p4 = new int 4 ; delete p1 ;delete p2 ;delete p3 ;delete p4 ;p2p1p3p42.4.1 new和delete操作符#includevoid main() int * p = NULL ; p = new int ( 89 ) ;/初始化存儲(chǔ)區(qū) if ( p = NULL )

29、 cout allocation faiuren; return ; cout *p ; delete p ;例用 new 算符建立簡(jiǎn)單對(duì)象 2.4.1 new和delete操作符#includevoid main() int * p = NULL ; p = new int ( 89 ) ;/初始化存儲(chǔ)區(qū) if ( p = NULL ) cout allocation faiuren; return ; cout *p ; delete p ;p例用 new 算符建立簡(jiǎn)單對(duì)象 2.4.1 new和delete操作符#includevoid main() int * p = NULL ; p

30、= new int ( 89 ) ;/初始化存儲(chǔ)區(qū) if ( p = NULL ) cout allocation faiuren; return ; cout *p ; delete p ;p89例用 new 算符建立簡(jiǎn)單對(duì)象 2.4.1 new和delete操作符#includevoid main() int * p = NULL ; p = new int ( 89 ) ;/初始化存儲(chǔ)區(qū) if ( p = NULL ) cout allocation faiuren; return ; cout *p ; delete p ;p89例用 new 算符建立簡(jiǎn)單對(duì)象 4.5.1 new 和

31、delete 操作符#includevoid main() int * p = NULL ; p = new int ( 89 ) ;/初始化存儲(chǔ)區(qū) if ( p = NULL ) cout allocation faiuren; return ; cout *p ; delete p ;89對(duì)象無名只能通過指針訪問例用 new 算符建立簡(jiǎn)單對(duì)象 p892.4.1 new和delete操作符#includevoid main() int * p = NULL ; p = new int ( 89 ) ;/初始化存儲(chǔ)區(qū) if ( p = NULL ) cout allocation faiure

32、n; return ; cout *p ; delete p ;p8989例用 new 算符建立簡(jiǎn)單對(duì)象 2.4.1 new和delete操作符#includevoid main() int * p = NULL ; p = new int ( 89 ) ;/初始化存儲(chǔ)區(qū) if ( p = NULL ) cout allocation faiuren; return ; cout *p ; delete p ;8989例用 new 算符建立簡(jiǎn)單對(duì)象 p2.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ; int i ; p

33、= new int 10 ; if ( p = NULL ) cout allocation faiuren ; return ; for ( i = 0 ; i 10 ; i + ) pi = 100 + i ; cout endl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 2.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p = NULL )

34、cout allocation faiuren ; return ; for ( i = 0 ; i 10 ; i + ) pi = 100 + i ; cout endl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 pti2.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p = NULL ) cout allocation faiuren ; re

35、turn ; for ( i = 0 ; i 10 ; i + ) pi = 100 + i ; cout endl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 pti2.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p = NULL ) cout allocation faiuren ; return ; for ( i = 0 ; i 10 ;

36、i + ) pi = 100 + i ; cout endl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 pti2.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p = NULL ) cout allocation faiuren ; return ; for ( i = 0 ; i 10 ; i + ) pi = 100 + i ; cout en

37、dl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 pti1001011021031041051061071081092.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p = NULL ) cout allocation faiuren ; return ; for ( i = 0 ; i 10 ; i + ) pi = 100 + i ; cout

38、endl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 pt10i100101102103104105106107108109|2.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p = NULL ) cout allocation faiuren ; return ; for ( i = 0 ; i 10 ; i + ) pi = 100 + i ;

39、cout endl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 pt100101102103104105106107108109|10i#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p = NULL ) cout allocation faiuren ; return ; for ( i = 0 ; i 10 ; i + ) pi = 100 + i ; cout endl ; fo

40、r ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 pt100101102103104105106107108109|10i2.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p = NULL ) cout allocation faiuren ; return ; for ( i = 0 ; i 10 ; i + ) pi = 100 + i ; cout endl

41、 ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 pt100101102103104105106107108109100 |10i2.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p = NULL ) cout allocation faiuren ; return ; for ( i = 0 ; i 10 ; i + ) pi = 100 + i ;

42、cout endl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 pt100101102103104105106107108109100 |10i2.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p = NULL ) cout allocation faiuren ; return ; for ( i = 0 ; i 10 ; i + ) pi = 1

43、00 + i ; cout endl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 pt100101102103104105106107108109100 |10i2.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p = NULL ) cout allocation faiuren ; return ; for ( i = 0 ; i 10 ; i +

44、 ) pi = 100 + i ; cout endl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 pt100101102103104105106107108109100 101 |10i#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p = NULL ) cout allocation faiuren ; return ; for ( i = 0 ; i 10 ; i + ) pi

45、= 100 + i ; cout endl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 p100101102103104105106107108109100 101 |t10i2.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p = NULL ) cout allocation faiuren ; return ; for ( i = 0 ; i 1

46、0 ; i + ) pi = 100 + i ; cout endl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 p100101102103104105106107108109100 101 |t10i2.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p = NULL ) cout allocation faiuren ; return ; for

47、( i = 0 ; i 10 ; i + ) pi = 100 + i ; cout endl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 p100101102103104105106107108109100 101 |t10i2.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p = NULL ) cout allocation faiuren ;

48、return ; for ( i = 0 ; i 10 ; i + ) pi = 100 + i ; cout endl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 p100101102103104105106107108109100 101 102 |t10i2.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p = NULL ) cout allo

49、cation faiuren ; return ; for ( i = 0 ; i 10 ; i + ) pi = 100 + i ; cout endl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 p100101102103104105106107108109100 101 102 |t10i2.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p =

50、 NULL ) cout allocation faiuren ; return ; for ( i = 0 ; i 10 ; i + ) pi = 100 + i ; cout endl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 p100101102103104105106107108109100 101 102 |t10i2.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ; int i ; p = new

51、int 10 ; if ( p = NULL ) cout allocation faiuren ; return ; for ( i = 0 ; i 10 ; i + ) pi = 100 + i ; cout endl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 p100101102103104105106107108109100 101 102 |t10i2.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ;

52、 int i ; p = new int 10 ; if ( p = NULL ) cout allocation faiuren ; return ; for ( i = 0 ; i 10 ; i + ) pi = 100 + i ; cout endl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 p100101102103104105106107108109100 101 102 103 |t10i#includevoid main() int * p = NULL , * t

53、 ; int i ; p = new int 10 ; if ( p = NULL ) cout allocation faiuren ; return ; for ( i = 0 ; i 10 ; i + ) pi = 100 + i ; cout endl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 p100101102103104105106107108109100 101 102 103 104 105 106 107 108 109 |t10i2.4.1 new和dele

54、te操作符#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p = NULL ) cout allocation faiuren ; return ; for ( i = 0 ; i 10 ; i + ) pi = 100 + i ; cout endl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 p100101102103104105106107108109100 101 102 10

55、3 104 105 106 107 108 109 |t10i2.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p = NULL ) cout allocation faiuren ; return ; for ( i = 0 ; i 10 ; i + ) pi = 100 + i ; cout endl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組

56、p100101102103104105106107108109100 101 102 103 104 105 106 107 108 109 |t10i2.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p = NULL ) cout allocation faiuren ; return ; for ( i = 0 ; i 10 ; i + ) pi = 100 + i ; cout endl ; for ( t = p ; t p+10 ; t + ) cou

57、t *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 p100101102103104105106107108109100 101 102 103 104 105 106 107 108 109 |t10i2.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p = NULL ) cout allocation faiuren ; return ; for ( i = 0 ; i 10 ; i + ) pi = 100 + i ;

58、 cout endl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 p100101102103104105106107108109100 101 102 103 104 105 106 107 108 109 |t10i2.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p = NULL ) cout allocation faiuren ; retur

59、n ; for ( i = 0 ; i 10 ; i + ) pi = 100 + i ; cout endl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 p100101102103104105106107108109t10i2.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p = NULL ) cout allocation faiuren ; r

60、eturn ; for ( i = 0 ; i 10 ; i + ) pi = 100 + i ; cout endl ; for ( t = p ; t p+10 ; t + ) cout *t ; cout endl ; delete p ;例用 new 算符建立動(dòng)態(tài)數(shù)組 p100101102103104105106107108109t10i以下標(biāo)方式訪問動(dòng)態(tài)數(shù)組2.4.1 new和delete操作符#includevoid main() int * p = NULL , * t ; int i ; p = new int 10 ; if ( p = NULL ) cout allocat

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論