C++(英文)-03

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

Chapter01---homepage03TheCinC++(Wakeyouup)Summary&ExercisesTheerabeforeC++FunctionPrototype&ControlDataTypes&OperatorsScoping&SpecifyingStorageAllocationCompositetypeFunctionAddressesTheerabeforeC++03TheCinC++(Wakeyouup)Summary&ExercisesFunctionPrototype&ControlDataTypes&OperatorsScoping&SpecifyingStorageAllocationCompositetypeFunctionAddressesWhatcanyoudowiththischapterAccordingtothetextbook:•Ifyou’veneverseenCbefore,youshouldreadthischapterover.•IfyouarefamiliarwiththeOldC,youwillfindsomethingnewinC++aswellasinStandardC.•IfyouarefamiliarwithStandardC,youshouldskimthroughthischapterlookingforfeaturesthatareparticulartoC++.NoteinthetextbookthatTherearesomefundamentalC++featuresintroducedhere,whicharebasicideasthatareakintothefeaturesinCoroftenmodificationstothewaythatCdoesthings.ThemoresophisticatedC++featureswillnotbeintroduceduntillaterchapters.Mysuggestion:readitroughly,makeyouawareoftheunfamiliarChapter01---homepageTheerabeforeC++Chapter01---homepage03TheCinC++(Wakeyouup)Summary&ExercisesTheerabeforeC++FunctionPrototype&ControlDataTypes&OperatorsScoping&SpecifyingStorageAllocationCompositetypeFunctionAddressesFunctionPrototype&Control03TheCinC++(Wakeyouup)Summary&ExercisesTheerabeforeC++DataTypes&OperatorsScoping&SpecifyingStorageAllocationCompositetypeFunctionAddressesAboutControlExecutionSomethingyoushouldpayattentionto:inttranslate(float,float);f1()inttranslate(floatx,floaty);intf1(void)voidf1(void)acceptablethebestintmain(intargc,char*argv[]){......return1;}intmain(void){}thebestYouMustRemember:Enoughinformationsonthefunctionshouldbeincluded,becausethereareoftenhugenumbersoffunctinosinC++programAboutFunctionprototypesChapter01---homepageFunctionPrototype&ControlAboutControlExecutionSomethingyoushouldpayattentionto:inttranslate(float,float);f1()inttranslate(floatx,floaty);intf1(void)voidf1(void)acceptablethebestintmain(intargc,char*argv[]){......return1;}intmain(void){}thebestYouMustRemember:Enoughinformationsonthefunctionshouldbeincluded,becausethereareoftenhugenumbersoffunctinosinC++programmerAboutFunctionprototypesFunctionPrototype&ControlAboutFunctionprototypesAboutControlExecutionAboutstructuredprogramming:•Allprogramsarecomposedofthethreecontrolstructures,suchassequence,selection,iteration(recursion).•EachblockintheprogramshouldonlyhaveoneentrypointandoneexitpointTheessenceisInordertoimprovetheclarity,quality,anddevelopmenttime,normalizingthephysicalstructureofacomputerprogrambyitscontrolstructuresChapter01---homepage03TheCinC++(Wakeyouup)Summary&ExercisesTheerabeforeC++FunctionPrototype&ControlDataTypes&OperatorsScoping&SpecifyingStorageAllocationCompositetypeFunctionAddressesDataTypes&Operators03TheCinC++(Wakeyouup)Summary&ExercisesTheerabeforeC++FunctionPrototype&ControlScoping&SpecifyingStorageAllocationCompositetypeFunctionAddressesKeepTheminYourMindAboutDataTypeinC++AboutOperatorsinC+++=,-=,*=,/=,&=,|=,^=e.g.lvalue@=exprislvalue=lvalue@exprsizeofexpr,sizeof(type)e.g.intn=sizeof(char);//nis4e.g.intm=sizeof5;//mis4e.g.intarray[]={1,2,3,4,5};//sizeof(array)is20++lvalue,lvalue++;--lvalue,lvalue–Notethat:valueofvariableVS.valueofexpressione.g.for“intx=5”;(++x)is6,xis6e.g.for“inty=5”;(y++)is5,yis6compositeoperator:sizeofoperator:(pre/post)increment/decrementoperator:Chapter01---homepageDataTypes&OperatorsKeepTheminYourMindAboutDataTypeinC++AboutOperatorsinC+++=,-=,*=,/=,&=,|=,^=e.g.lvalue@=exprislvalue=lvalue@exprsizeofexpr,sizeof(type)e.g.intn=sizeof(char);//nis4e.g.intm=sizeof5;//mis4e.g.intarray[]={1,2,3,4,5};//sizeof(array)is20++lvalue,lvalue++;--lvalue,lvalue–Notethat:valueofvariableVS.valueofexpressione.g.for“intx=5”;(++x)is6,xis6e.g.for“inty=5”;(y++)is5,yis6compositeoperator:sizeofoperator:increment/decrementoperator:DataTypes&Operatorstypeid(type),typeid(expr)e.g.while(typeid(obj)==typeid(string)){...}expr,expre.g.intn=0;n=(3,5,7,9,10);//nis10e.g.intn=0;n=3,5,7,9,10;//nis3newtype,newtype(expr_list),newtype[]e.g.char*pC=newchar[8*sizeof(char)+1];e.g.int*pN=newint;e.g.char*p=newchar(1);e.g.ClassType*p=newClassType(arg_list);typeidoperator:commaoperator:newoperator:KeepTheminYourMindAboutDataTypeinC++typeid(type),typeid(expr)e.g.while(typeid(obj)==typeid(string)){...}expr,expre.g.intn=0;n=(3,5,7,9,10);//nis10e.g.intn=0;n=3,5,7,9,10;//nis3newtype,newtype(expr_list),newtype[]e.g.char*pC=newchar[8*sizeof(char)+1];e.g.int*pN=newint;e.g.char*p=newchar(1);e.g.ClassType*p=newClassType(arg_list);typeidoperator:commaoperator:newoperator:delete,delete[]e.g.int*p=newint(2);deletep;e.g.int*p=newint[10];delete[]p;e.g.int*p=newint[10];deletep;//sometimesmemoryleak!!deleteoperator:Otheroperators:AboutOperatorsinC++DataTypes&OperatorsKeepTheminYourMindAboutDataTypeinC++AboutOperatorsinC++delete,delete[]e.g.int*p=newint(2);deletep;e.g.int*p=newint[10];delete[]p;e.g.int*p=newint[10];deletep;//memoryleak!!deleteoperator:otheroperators:DataTypes&OperatorsAboutOperatorsinC++KeepTheminYourMindbool,true,falseconditional/relational/ect.expressioneproduceboolresulte.g.boolb=true;//bestwaye.g.boolb=3;//acceptablee.

1 / 25
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功