c語言難點(diǎn)及分析(DifficultiesandanalysisofClanguage)_第1頁
c語言難點(diǎn)及分析(DifficultiesandanalysisofClanguage)_第2頁
c語言難點(diǎn)及分析(DifficultiesandanalysisofClanguage)_第3頁
c語言難點(diǎn)及分析(DifficultiesandanalysisofClanguage)_第4頁
已閱讀5頁,還剩31頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

c語言難點(diǎn)及分析(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(級(jí)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(級(jí)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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(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)論