arrays - penn state brandywine engineering阵列-宾州白兰地工程

arrays - penn state brandywine engineering阵列-宾州白兰地工程

ID:33767610

大小:129.50 KB

页数:35页

时间:2019-02-28

arrays - penn state brandywine engineering阵列-宾州白兰地工程_第1页
arrays - penn state brandywine engineering阵列-宾州白兰地工程_第2页
arrays - penn state brandywine engineering阵列-宾州白兰地工程_第3页
arrays - penn state brandywine engineering阵列-宾州白兰地工程_第4页
arrays - penn state brandywine engineering阵列-宾州白兰地工程_第5页
资源描述:

《arrays - penn state brandywine engineering阵列-宾州白兰地工程》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、Chapter7:ArraysThevariablesusedsofarhaveallhadacommoncharacteristic:Eachvariablecouldonlybeusedtostoreonevalueatatime.Frequently,wemayhaveasetofvalues,allofthesamedatatype,thatformalogicalgroup.Asimplelistcontainingindividualitemsofthesamescalardatatypeiscalledaone-di

2、mensionalarray.Inthischapter,wewillstudyhowone-dimensionalarraysaredeclared,initialized,storedinsideacomputer,andused.7.1One-DimensionalArraysAone-dimensionalarray(oralist,oravector)isagroupofrelatedvalueswiththesamedatatypethatisstoredusingagroupname.Thegroupnameisre

3、ferredtoasthearrayname.Theitemsinthelistcanbedeclaredasasingleunitandstoredunderacommonvariablenamecalledthearrayname.Forexample,supposethatwewouldliketostorefiveexamgradesinanarray,namedgrade,thedeclarationstatementwillbe:intgrade[5];Otherexamples:charcode[4];//anarr

4、ayoffourcharactervaluesfloatprices[6];doubleamount[100];Eachelementinanarrayiscalledanelementorcomponentofthearray.35Chapter7:ArraysTheindividualelementsstoredinthearrayarestoredsequentially,withthefirstarrayelementstoredinthefirstreservedlocation,thesecondelementstor

5、edinthesecondreservedlocation,andsoon.Toaccessindividualelementsinanarray,youusethenameofthearrayandtheelement'sposition.Thispositioniscalledtheelement'ssubscriptorindexvalue.Forasingle-dimensionedarraythefirstelementhasasubscriptof0.Theindicesofanarrayaresaidtobezero

6、relative.Forexample:intgrade[5];grade[0]referstothefirstgradestoredinthegradearray.grade[1]referstothesecondgradestoredinthegradearray.grade[0]grade[1]grade[2]grade[3]grade[4]anintegeranintegeranintegeranintegeranintegerelement1element2element3element4element5Internal

7、ly,thecomputerusestheindexasanoffsetfromthearray'sstartingposition.Theindextellsthecomputerhowmany35Chapter7:Arrayselementstoskipover,startingfromthebeginningofthearray,togettothedesiredelement.35Chapter7:ArraysIn-ClassExercise:1.Writearraydeclarationsforthefollowing:

8、a.alistof100floating-pointvoltagesb.alistof30characters,eachrepresentingacodec.alistof100integersUsingSubscriptedVariablesSu

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。