版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
c語言難點及分析(DifficultiesandanalysisofClanguage)CLanguagedifficultiesexergyanalysis[Posted]ThisarticlemainlyintroducessomeoftheminrevisionCTheprocessoflanguageIpersonallythinkthatamorefocusedlocalbettergraspthisSomekeypointswillmakeitrightCTheuseofmorehandy.Alsowillincludesomeofthedetails,errorproneareas.ThemaincontentsofthepackageTheexergyscopeofvariablesandstoragetypes,functions,arrays,strings,pointer,filelist,etc..SomeofthemostbasicconceptsThisisnottoexplaintheonlyhopetohaveawordortwotothesameLanguagebeginnersprovidealittlelearningandhands-onprocessHelp.VariablescopeandstorageclassincludedUnderstandthebasictypesofvariablesafterwewanttofurtherunderstandthestoragecategoriesandthevariablescopeofitsproblems.ThevariablesofclasssubcategoriesStaticvariablesinleftvariablevaluestillretainsthefunctionAutomaticvariablelocalvariableregistervariableOnlywiththestaticvariablesinglobalvariablesinthisdocumentNonstaticvariableswillallowtheuseofotherdocumentsforapointBesshitypevariableclassstaticlocalvariablerateexergyfunctionStaticrateofthisdocumentexergyStaticstoragevariableNonstaticglobal/externalvariablerateotherfilereferenceexergyAutomaticvariableregistervariableDynamicstoragevariableFormalparameterexternThetypevariableisstoredinprocessingofmultifileproblemsoftencanbeusedinthedefinitioninafileExternVariablesthatindicatethatthisvariableisusedforotherfiles.BythewayIencounteredindoingclassbasedOutofmemoryTheerrorinthefileandputitinalongIncludePayattentiontoyourwritinginocclusionThe*.hTouse〃〃Noneed<>Exergyincanplayacertaineffect.StaticTypeinthereadingprogramtowritetheresultsoftheexaminationquestionsIsthetestcenter.MostofthetimetheprogramwillhavemultiplevariablesdefinedindifferentfunctionintestinWhatisthevalueofthesamevariableatdifferentlocations?.ThemainistofollowaprincipleinaslongasthefunctionisnotdefinedVariableswiththeglobalvariablerateratherthanMainExergyinglobalandlocalvariablesinthelocalvariablenameOfcourse,butalsoplayaroleinattentiontothedistinctionbetweenstaticandautomaticvariables.ThefunctionThemostbasicunderstandingoffunctionisfromthatmainThewordbeginsinastatementtobegintofeelWriteinMainThereisnotagoodModyWhychooseoutin.Infact,thisisbecausethefunctionisnotenoughSkilledintheuseofotherwisethefunctionwillbringgreatconveniencetoourprogramming.WeneedtoknowthereturnvalueofthefunctionTypeinthetypeoftheparametersintheformandthefunctioniscalled.Apriorfunctiondescriptioncanalsoserveasagoodreminder.TheparameterandargumentinthecallingfunctionwritteninparenthesesistheargumentfunctionitselfTheparameterisusedindrawingaflowchartwithparallelogramtransmissionparameters.AnotherproblemthereactionfunctionistheapplicationexampleoftherecursiveIstartedaheadacheisalwaysslowbutaccordingtotheteacher'smethodtotheprocessofrecursivestepbysteptodrawouttheaccuratepatientlearningeffectisbetterthanWewillfeelbetterbyusingthisrecursionisquitecleverbutinfacttheeightqueens,thefamoustowerofHanoi.Thequestionsarerecursive.ForexampleLongfun(intn)(Longs;If(n==l||n==2)s=2;Elses=n-fun(n-l);Returns;)(main)Printf("%ld”,fun(4));}arrayDividedintoone-dimensionalandmultidimensionalarrayswithinthestoragemethodofpaintingformisactuallythewordswouldbeclearataglanceThesametypeofvariablesisarrangedinanorderlyway.SothisisthemostinthetreatmentoftheexergymoredataTheapplicationscopeofthesituationinthearrayisverywide.Thepracticalapplicationofspecificexamplesoftheinconvenienceandthevastmajorityofthewriter'spersonalcombinedwithpointerlearningArraysare,toagreatextent,aforeshadowingoflearningpointers.SeveralbasicexercisesshouldbeunderstoodasthebasisforthefoundationThatis,forarrayassignmentprinting,sortingexergybubblesortandselectionsort,findin.ThesearetheinevitablereactionbutifusedcycleratetoratecanbealittlebitofthecycleexpansionratewillbecomeWhenyouwritemorefamiliarwiththerateofafunctionwillfirstfindouttheinternalrulesofgooduserate,anotherTheouterarrayparameterswhentherateofone-dimensionalTherecanbetwoemptyfirstrateロItcanbeempty,butno.TwoロSizemustbespecified.BubblesortfunctionexergymethodVoidbubble(int,a[],int,n)IInt,I,J,k;For(i=l,i<n,i++)For(j=0;j<n-i;j++)If(a[j]>a[j+l])(K=a[j];A[j]=a[j+1];A[j+l]=k;SelectionsortfunctionexergyVoidsort(int,aロ,int,n){Int,I,J,K,t;For(i=0,i<n-l,i++){K=i;For(j-i+1;j<n;j++)If(a[k]<a[j])k=j;If(k,=i){t=a[i];A[i]=a[k];A[k]=t;BinarysearchfunctionoftheoriginalarrayorderedtheexergyrateVoidsearch(int,a口,int,N,int,x)(Int,left=0,right=n-1,mid,flag=0;(while(flag-0)and(leftく=right))IMid=(left+right)/2;If(x==a[mid])(Printf(〃%d%d","X","mid");Flag=1;Elseif(x<a[mid])right=mid-l;Elseleft=mid+l;Somecommonlyusedalgorithmsand}judgmentinfactorialxFibanacciSequenceinarbitraryhexadecimalconversioninYangHuiTrianglecalculation,etc..ThestringThestringisactuallyanarrayofpointersintheexergyrateScanfTheinputcolumndoesnotneedtobeaddedinfrontThesymbolsinthearraynamebecausethecharacteritselfrepresents.Itisworthnotingthattheendofthestring‘、〇’InsuchasIfnowordsinastringislikelynotthenormalprint.AnotheristhedefinitionandassignmentofstringsIhaveaproblemincomparingthemachineoperationisalwaysupanddowntofindinprintgarbledstringAcircleinthelastfindingisbecausecharinsteadofchar*name;name[10];theformerdidnotsaynotowherewilldeterminethesizewillleadtoerrorsinthecodeverydeepimpression.AnotherassignmentinthestringisalsoneedtopayattentiontoinifyouareusingwordsincharacterpointercandefinetheWhentheinitialvalueintheChar*a="Abcdefg”;alsoinanassignmentstatementassignmentinchar*a;A="Abcdefg”;butifyouareusinganarrayofcharactersinwordsonlyinthedefinitionoftheinitialvalueinthewholeChara[5]={"ABCD"};Notintegralassignmentinassignmentstatement.ThefollowinglistofstringfunctionscommonlyusedintherealizationoftheirownwillFunction,function,callform,remarkstring,copyfunctionstrcpy(char*,char*),thelattercopytotheformerStringappendfunctionStrcat(char*,char*)ThelatterisappendedtotheformerreturnaftertheformersotheformeremptyBelargeenoughStringcomparisonfunctionStrCmp(char*,char*)Theformerisequalto,lessthan,greaterthanthelatterwhenreturns0,positive,Negativevalue.NotelengthisnotcharacterASThesizeofCIIcodecanbeusedforinalphabeticalorder.StringlengthStrlen(char*)Returnsthelengthofthestringdoesnotincludea、0'.escapecharacterOnecharacter.String->integerATOI(char*)Itoa(int,char*,int)Integer->stringtypedoveryusefullessonwhenSprintf(char*formattedtransport)IntheAssignedtotheandprintoutthestring.ClassisalsousedwhensettingMoreconvenienttonoteexergystringisnotallowedtodoOrexergyTheoperationcanonlyusethestringcomparisonfunctionThepointerpointercanbesaidtobeCincludedThemostcriticalareasinthelanguagePointerThenameforthisconceptUnderstandingisverygraphic.WeneedtoknowpointervariablevaluesinthepointervariablesstoredinthevalueofthemeanIntheaddressoftheneedle.Thebasictypesofthepointervariablesdefinedintheformofexergy*PointervariablenameIn**"Istherepresentativeofthisisapointertothebasetypepointervariablerateratherthanthemeaningofthecontent.Wheninuserateas*ptr=aWhenocclusionExpressPTRWhatisintheaddressthatispointingtoisA.Atypicalpointerandasimpleapplicationexampleistheexchangerateattherateofswapprogram(intc,intd){Intt;T=c;C-d;D=t;)(main)(Int,a=2,b=3;Swap(a,B);Printf(級d",〃%d","a","B");}ThisisnotpossibleAandBTheexchangerateisactuallyanumericalparameterinthefunctionofexchangerateItdoesn'tmakeanydifferencetothearguments.Nowwiththerateofpointertypedataasargumentratechangedasswap(#3333FF*pl,intexergy*p2){Intt;T=*pl;*pl=*p2;*p2=t;)Main(){Int,a=2,b=3;Int,*ptrl,*ptr2;Ptrl=&a;Ptr2=&b;Swap(Prtl,ptr2);Printf(級d",〃%d","a","B");}so...SwapZhongYouZhongPl,P2TochangethecontentofexergyisAExergyBThevaluesareswapped.Thepointercanperformincreaseanddecreaseoperationwithexergy++Wecanseethelawofexergyoperator+sTakethepointervariableplus1later*s++Afterthepointervariablereferstothecontent,splus1(*S)++Referstothecontentofthepointervariableplus1pointersandarraysarevirtuallythesamenamearrayexergycanberegardedasaone-dimensionalarrayofconstexergyPtr=&b[〇]ThefollowingnotationisequivalentinA[3]Equivalentto(a+3)Ptr[3]Equivalentto(ptr+3)seebelow,withapointertoachievetheirownATOIRateofstringtype->ThefunctionofintATOIintegerexergy(char*s)iInt,signal,m=0;If(*s=='+'II*s=='-')/**/symbolstojudgewhetherthereisSign=(*s++=='+')?1:-1;/**/operatorusedthreemeshWhile(*s!=‘、0’)/*operationforeachcharacter.M=m*10+(*s-'0');S++;/**/tothenextcharacterReturnm*sign;}pointingtopointervariablesinmultidimensionalarraysisalsoamorewidespreaduse.Forexample,arraysA[3][4]InARepresentativeTheactualisthetwo-dimensionalarrayinthefirstaddressZeroThefirstaddressisapointervariablein.andA+1ItisnotsimplyaddedtothenumericalvalueOneItisnottherepresentativeinA[0][l]ButintheOneTheheadofthelineAddressin&a[l][0].Pointervariablescommonlyusedandtheuseofpointersasparameterstootherfunctionistofunction.LookatthefollowinglinesofcodeVoidInput(ST*);VoidOutput(ST*);VoidBubble(ST*);VoidFind(ST*);voidFailure(ST*);Thefive/*functiondeclarationfunctionisapointertoaSTtyperatepriordefinedpointervariableasaparameterinexergystructureofnoreturnvalue.*/Void(*process[5])(ST*),={Input,Output,Bubble,Find,Failure);/"processiscalledtoprovide5functionsofdifferentfunctionswereselected(exergytoafunctionpointerarray.Printf("\nChoose:\n?");Scanf("%d”,&choice);If(choice>=0&&choiceく=4)("process[choice])(a);/"callthecorrespondingfunctiontoachievedifferentfunctions;intheapplication/shortpointerisveryflexibleandwideinnotabletofinishitintwowordsorthreeafewcasesinThesonisanintroductionintheactualprogrammingwillgraduallyfoundthattheuseofpointerscanbringconvenienceandefficiency.ThefileFunctioncalldescriptionFopen(path,openmode)opensthefileFclose(FILE")PreventfrombeingmisusedlaterFgetc(FILE*)ReadsacharacterfromafileFputc(CH,FILE*)Writethecharactersrepresentedbychintothisfile,fgets(FILE*)ReadalinefromthefileFputs(FILE*)WritealinetothefileFprintf(FILE*,formatstring),outputtableColumnexergyWritedatatoafileFscanf(FILE*,formatstring),inputtableColumnexergyReadfromfileThefwriterateinsizeofinthenaddressintheFILEexergyrate*exergyWritetheNsizeofdataintheaddressintothefileTheFREADrateinsizeofinthenaddressintheFILEexergyrate*exergyReadtheNsizeofdatainthefileintotheaddressRewindrateFILE*putthefilepointerbacktotheexergyheaderFseekFILE*xin0/1/2rateinexergymovedthefilepointer.Thesecondparameteristhedisplacementin0representstheshiftin1fromscratchFromthecurrentpositionin2onbehalfofrepresentativesfromtheendoffiletransfer.Feof(FILE*)WhetherornottheendofthefileisjudgedFileopenmodeROpenonlyreadablefilesFortheestablishmentofthewrittenfileiftherehasbeenerasedtheoriginaldataAOpenorestablishafilethatappendsdatatotheendofafileR+OpenthefileusedtoupdatethedataW+AdatafileusedtoupdatetheoriginaldataiftherehasbeenerasedA+Fortheestablishmentofopenorupdatethefiledataisappendedtotheabovedocumentsforendnotestextfileiftheoperationisabinaryfileintheletteradded〃BThebiggestpurposeofourfileistokeepthedata.SowhentousethedatainthefileItistoreaddataintoadatastructurewithgeneralexergypreservationtothestructureofthenodetofacilitatemanagementinThestructurecanbeoperated.Forexample,thefileAa.dataWhatisstoredinThirtyStudentachievementandotherinformationtotheTheinformationofthetraversalresultsoutput,sortandsearchforitsworkwhenweputtheseinformationReadintoanarrayofstructuresintheoperationofthearray.Thefollowingexample#include<stdio.h>#include<stdlib.h>#defineN30typedefstructstudent/*definitionofstudentachievementinformationstoragearray.Char*name;IntChinese;Intmaths;Intphy;Inttotal;}ST;(main)[STa[N];AstudentinformationstorageN/**/arrayFILE*fp;Void("process[3])(ST*)={Output,Bubble,Find};/**/threefunctionrelatedfunctionsInt,choice,i=0;Show();Printf("\nChoose:\n?");Scanf("%d”,&choice);While(choice>=0&&choiceく=2)Fp=fopen("aa.dat","RB");For(i=0;i<N;i++)FREAD(&a[i],sizeof(ST),1,FP);/*tofiletheinformationstoredinthearraytoreadonebyone.Fclose(FP);("process[choice])(a);/*thepointerintheselectionoperation.Printf("\n");Show();Printf("\n?");Scanf("%d”,&choice);})Void,Show()(Printf(\n****Choices:****\n0.Display,the,data,form\nl.Bubble,it,according,,to,the,total,score\n2.Search\n3.Quit,\n,VoidOutput(ST*a)/**/outputbytheinformationstoredinthefileIInt,I,t=0;Printf("NameChineseMathsPhysicsTotal\n");For(i=0;i<N;i++)IT=a[i].chinese+a[i].maths+a[i].phy;A[i].total=t;Printf("%4s%8d%8d%8d%8d\n",a[i].name,a[i].Chinese,a[i].maths,a[i].phy,a[i].total);VoidBubble(ST*a)/*sortandoutputinthearray.Int,I,pass;STm;For(pass=0;passくNT;pass++)For(i=0;i<N-l;i++)If(a[i].total<a[i+l].total){M=a[i];/**/a[i]=a[i+l]exchangestructure;A[i+l]=m;)Output(a);)VoidFind(ST*a)(Int,I,t=l;Charm[20];Printf("\nEnterthenameyouwant:);Scanf("如",m);For(i=0;i<N;i++)If(!StrCmp(m,a[i].name))/*underthenamematchingthesearchresultsoutput.[Printf("\nThe,result,is:\n%s,Chinese:%d,Maths:%d,Physics:%d,Total:%d\n",m,a[i].Chinese,a[i].maths,a[i].phy,a[i].total);T=0;)If(T)Printf("\nThename,is,not,in,the,list,\n");}inthelistLinkedlistCAnotherdifficultpointinlanguage.Itinvolvesnodes,dynamicallocationspace,andsoon.Usestr
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 保險合規(guī)考試試題及答案
- 大數(shù)據(jù)驅(qū)動的職業(yè)性放射病風(fēng)險預(yù)測研究-1
- 大數(shù)據(jù)賦能精準(zhǔn)醫(yī)學(xué)人才培養(yǎng)模式
- 大數(shù)據(jù)在慢病健康促進(jìn)中的應(yīng)用
- 導(dǎo)演考試題及答案
- 多維度分層在個體化手術(shù)中的應(yīng)用
- 2025年大學(xué)大二(商務(wù)策劃)方案撰寫綜合測試題及答案
- 2025年高職旅游服務(wù)與管理(導(dǎo)游詞撰寫)試題及答案
- 2025年中職(工業(yè)機器人技術(shù)應(yīng)用)機器人傳感器應(yīng)用試題及答案
- 2025年高職(環(huán)境監(jiān)測技術(shù))環(huán)境工程原理實務(wù)試題及答案
- 吳江三小英語題目及答案
- 2025年事業(yè)單位筆試-河北-河北藥學(xué)(醫(yī)療招聘)歷年參考題庫含答案解析(5卷套題【單選100題】)
- 集團(tuán)債權(quán)訴訟管理辦法
- 鋼結(jié)構(gòu)施工進(jìn)度計劃及措施
- 智慧健康養(yǎng)老服務(wù)與管理專業(yè)教學(xué)標(biāo)準(zhǔn)(高等職業(yè)教育??疲?025修訂
- 珠寶首飾售后服務(wù)與保修合同
- 2025年廣東省惠州市惠城區(qū)中考一模英語試題(含答案無聽力原文及音頻)
- 煤礦皮帶輸送機跑偏原因和處理方法
- 征兵體檢超聲診斷
- 創(chuàng)傷后應(yīng)激障礙的心理護(hù)理
- 醫(yī)療項目年度總結(jié)模板
評論
0/150
提交評論