计算机C语言专业外文翻译.docx

上传人:b****8 文档编号:29486354 上传时间:2023-07-23 格式:DOCX 页数:6 大小:19.52KB
下载 相关 举报
计算机C语言专业外文翻译.docx_第1页
第1页 / 共6页
计算机C语言专业外文翻译.docx_第2页
第2页 / 共6页
计算机C语言专业外文翻译.docx_第3页
第3页 / 共6页
计算机C语言专业外文翻译.docx_第4页
第4页 / 共6页
计算机C语言专业外文翻译.docx_第5页
第5页 / 共6页
点击查看更多>>
下载资源
资源描述

计算机C语言专业外文翻译.docx

《计算机C语言专业外文翻译.docx》由会员分享,可在线阅读,更多相关《计算机C语言专业外文翻译.docx(6页珍藏版)》请在冰豆网上搜索。

计算机C语言专业外文翻译.docx

计算机C语言专业外文翻译

计算机C语言专业外文翻译

CAHistoryofCCandCTheCprogramminglanguagewascreatedinthespiritoftheCandCprogramminglanguages.Thisaccountsforitspowerfulfeaturesandeasylearningcurve.ThesamecantbesaidforCandCbutbecauseCwascreatedfromthegroundupMicrosofttookthelibertyofremovingsomeofthemoreburdensomefeatures—suchas

pointers.ThissectiontakesalookattheCandClanguagestracingtheirevolutionintoC.TheCprogramminglanguagewasoriginallydesignedforuseontheUNIXoperatingsystem.CwasusedtocreatemanyUNIXapplicationsincludingaCcompilerandwaseventuallyusedtowriteUNIXitself.ItswidespreadacceptanceintheacademicarenaexpandedtoincludethecommercialworldandsoftwarevendorssuchasMicrosoftandBorlandreleasedCcompilersforpersonalcomputers.TheoriginalWindowsAPIwasdesignedtoworkwithWindowscodewritteninCandthelatestsetofthecoreWindowsoperatingsystemAPIsremaincompatiblewithCtothisday.FromadesignstandpointClackedadetailthatotherlanguagessuchasSmalltalkhadalreadyembraced:

theconceptofanobject.YoulllearnmoreaboutobjectsinChapter8quotWritingObject-OrientedCode.quotFornowthinkofanobjectasacollectionofdataandasetofoperationsthatcanbeperformedonthatdata.Object-stylecodingcouldbeaccomplishedusingCbutthenotionofanobjectwasnotenforcedbythelanguage.Ifyouwantedtostructureyourcodetoresembleanobjectfine.Ifyoudidntfine.Creallydidntcare.Objectswerentaninherentpartofthelanguagesomanypeopledidntpaymuchattentiontothisprogrammingparadigm.Afterthenotionofobject-orienteddevelopmentbegantogainacceptanceitbecameclearthatCneededtoberefinedtoembracethisnewwayofthinkingaboutcode.Cwascreatedtoembodythisrefinement.ItwasdesignedtobebackwardlycompatiblewithCsuchthatallCprogramswouldalsobeCprogramsandcouldbecompiledwithaCcompiler.ThemajoradditiontotheClanguagewassupportforthisnewobjectconcept.TheClanguageaddedsupportforclasseswhicharequottemplatesquotofobjectsandenabledanentiregenerationofCprogrammerstothinkintermsofobjectsandtheirbehavior.TheClanguageisanimprovementoverCbutitstillhassomedisadvantages.CandCcanbehardtogetahandleon.Unlikeeasy-to-uselanguageslikeVisualBasicCandCareveryquotlowlevelquotandrequireyoutodoalotofcodingtomakeyourapplicationrunwell.Youhavetowriteyourowncodetohandleissuessuchasmemorymanagementanderrorchecking.CandCcanresultinverypowerfulapplicationsbutyouneedtoensurethatyourcodeworkswell.Onebugcanmaketheentireapplicationcrashorbehaveunexpectedly.BecauseoftheCdesigngoalofretainingbackwardcompatibilitywithCCwasunabletobreakawayfromthelowlevelnatureofC.MicrosoftdesignedCtoretainmuchofthesyntaxofCandC.DeveloperswhoarefamiliarwiththoselanguagescanpickupCcodeandbegincodingrelativelyquickly.ThebigadvantagetoChoweveristhatitsdesignerschosenottomakeitbackwardlycompatiblewithCandC.Whilethismayseemlikeabaddealitsactuallygoodnews.CeliminatesthethingsthatmakesCandCdifficulttoworkwith.BecauseallCcodeisalsoCcodeChadtoretainalloftheoriginalquirksanddeficienciesfoundinC.CisstartingwithacleanslateandwithoutanycompatibilityrequirementssoitcanretainthestrengthsofitspredecessorsanddiscardtheweaknessesthatmadelifehardforCandCprogrammers.IntroducingCCthenewlanguageintroducedinthe.NETFrameworkisderivedfromC.HoweverCisamodernobjected-orientedfromthegrounduptype-safelanguage.LanguagefeaturesThefollowingsectionstakeaquicklookatsomeofthefeaturesoftheClanguage.Ifsomeoftheseconceptsdontsoundfamiliartoyoudont

worry.Allofthemarecoveredindetailinlaterchapters.ClassesAllcodeanddatainCmustbeenclosedinaclass.Youcantdefineavariableoutsideofaclassandyoucantwriteanycodethatsnotinaclass.Classescanhaveconstructorswhichexecutewhenanobjectoftheclassiscreatedandadestructorwhichexecuteswhenanobjectoftheclassisdestroyed.Classessupportsingleinheritanceandallclassesultimatelyderivefromabaseclasscalledobject.Csupportsversioningtechniquestohelpyourclassesevolveovertimewhilemaintainingcompatibilitywithcodethatusesearlierversionsofyourclasses.AsanexampletakealookataclasscalledFamily.Thisclasscontainsthetwostaticfieldsthatholdthefirstandlastnameofafamilymemberaswellasamethodthatreturnsthefullnameofthefamilymember.classClass1publicstringFirstNamepublicstringLastNamepublicstringFullNamereturnFirstNameLastNameNoteSingleinheritancemeansthataCclasscaninheritfromonlyonebaseclass.Cenablesyoutogroupyourclassesintoacollectionofclassescalledanamespace.Namespaceshavenamesandcanhelporganizecollectionsofclassesintologicalgroupings.AsyoubegintolearnCitbecomesapparentthatallnamespacesrelevanttothe.NETFrameworkbeginwithSystem.MicrosofthasalsochosentoincludesomeclassesthataidinbackwardscompatibilityandAPIaccess.TheseclassesarecontainedwithintheMicrosoftnamespace.DatatypesCletsyouworkwithtwotypesofdata:

valuetypesandreferencetypes.Valuetypesholdactualvalues.Referencetypesholdreferencestovaluesstoredelsewhereinmemory.Primitivetypessuchascharintandfloataswellasenumeratedvaluesandstructuresarevaluetypes.Referencetypesholdvariablesthatdealwithobjectsandarrays.Ccomeswithpredefinedreferencetypesobjectandstringaswellaspredefinedvaluetypessbyteshortintlongbyteushortuintulongfloatdoubleboolcharanddecimal.Youcanalsodefineyourownvalueandreferencetypesinyourcode.Allvalueandreferencetypesultimatelyderivefromabasetypecalledobject.Callowsyoutoconvertavalueofonetypeintoavalueofanothertype.Youcanworkwithbothimplicitconversionsandexplicitconversions.Implicitconversionsalwayssucceedanddontloseanyinformationforexampleyoucanconvertaninttoalongwithoutlosinganydatabecausealongislargerthananint.Explicitconversionsmaycauseyoutolosedataforexampleconvertingalongintoanintmayresultinalossofdatabecausealongcanholdlargervaluesthananint.Youmustwriteacastoperatorintoyourcodetomakeanexplicitconversionhappen.Cross-ReferenceRefertoChapter3quotWorkingwithVariablesquotformoreinformationaboutimplicitandexplicitconversions.Youcanworkwithbothone-dimensionalandmultidimensionalarraysinC.Multidimensionalarrayscanberectangularinwhicheachofthearrayshasthesamedimensionsorjaggedinwhicheachofthearrayshasdifferentdimensions.Classesandstructurescanhavedatamemberscalledpropertiesandfields.Fieldsarevariablesthatareassociatedwiththeenclosingclassorstructure.YoumaydefineastructurecalledEmployeeforexamplethathasafieldcalledName.IfyoudefineavariableoftypeEmployeecalledCurrentEmployeeyoucanretrievetheemployeesnamebywritingCurrentEmployee.Name.Propertiesarelikefieldsbutenableyoutowritecodetospecifywhatshouldhappenwhencodeaccessesthevalue.IftheemployeesnamemustbereadfromadatabaseforexampleyoucanwritecodethatsaysquotwhensomeoneasksforthevalueoftheNamepropertyreadthenamefromthedatabaseandreturnthenameasastring.quotFunctionsAfunctionisacallablepieceofcodethatmayormaynotreturnavaluetothecodethatoriginallycalledit.AnexampleofafunctionwouldbetheFullNamefunctionshownearlierinthischapterinthe

Familyclass.Afunctionisgenerallyassociatedtopiecesofcodethatreturninformationwhereasamethodgenerallydoesnotreturninformation.Forourpurposeshoweverwegeneralizeandrefertothembothasfunctions.Functionscanhavefourkindsofparameters:

Inputparametershavevaluesthataresentintothefunctionbutthefunctioncannotchangethosevalues.Outputparametershavenovaluewhentheyaresentintothefunctionbutthefunctioncangivethemavalueandsendthevaluebacktothecaller.Referenceparameterspassinareferencetoanothervalue.Theyhaveavaluecomingintothefunctionandthatvaluecanbechangedinsidethefunction.Paramsparametersdefineavariablenumberofargumentsinalist.CandtheCLRworktogethertoprovideautomaticmemorymanagement.Youdontneedtowritecodethatsaysquotallocateenoughmemoryforanintegerquotorquotfreethememorythatthisobjectwasusing.quotTheCLRmonitorsyourmemoryusageandautomaticallyretrievesmorewhenyouneedit.ItalsofreesmemoryautomaticallywhenitdetectsthatitisnolongerbeingusedthisisalsoknownasGarbageCollection.Cprovidesavarietyofoperatorsthatenableyoutowritemathematicalandbitwiseexpressions.Manybutnotalloftheseoperatorscanberedefinedenablingyoutochangehowtheoperatorswork.Csupportsalonglistofstatementsthatenableyoutodefinevariousexecutionpathswithinyourcode.Flowcontrolstatementsthatusekeywordssuchasifswitchwhileforbreakandcontinueenableyourcodetobranchoffintodifferentpathsdependingonthevaluesofyourvariables.Classescancontaincodeanddata.Eachclassmemberhassomethingcalledanaccessibilityscopewhichdefinesthemembersvisibilitytootherobjects.Csupportspublicprotectedinternalprotectedinternalandprivateaccessibilityscopes.VariablesVariablescanbedefinedasconstants.Constantshavevaluesthatcannotchangeduringtheexecutionofyourcode.Thevalueofpiforinstanceisagoodexampleofaconstantbecauseitsvaluewontbechanging

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1