资源描述:
《c函数、数组、指针和调试器gdb--函数--变量的访问控制和存储类别》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、C函数.数组.指针和调试器gdb—函数一变量的访问控制和存储类1,variableaccesscontrolVariablesarcdividedintotwocategoriesaccordingtotheiraccessscopeintheprogram:localvariablesandglobalvariables・Alocalvariableisavariabledefinedwithinafunction.Itisonlyvalidinsideafunctionandcannotbeaccessedo
2、utsideofafunction.Suchas:(main)Intfunctionl(int,a,int,b)Floatfunction2(inta)Intm;Thevariablesdefinedwithineachfunctioncanonlybeusedwithinthefunction,butonlywithinthefunction.Themainfunctionisnoexception,andthevariablesIandjdefinedbythemainfunctioncanonlybeuse
3、dintheprimaryfunction.Differentfunctionscanbedefinedwiththesamenamevariable,theydonothaveanyrelationship,suchasthefunctionlfunctionalsodefinesavariablenamedI,anditisthemainfunctionofthedefinitionofinternalvariableIdoesnothaveanyrelationship・Theformalparameter
4、isalsoalocalvariable,sotheparameterfunctionloftheAhasnothingtodowiththeparameterfunction2ofthea.SuchusedoesnotviolatetherulesoftheClanguage・Asourcefileisusuallycomposedofmultiplefunctions.Ifavariableisnotdefinedinanyfunction,thisvariableistheglobalvariable・Gl
5、obalvariablescanbeaccessedbyanyfunctionwithinthesourcefile・Itsrangeofvaliditystartsfromthedefinitionofthevariabletotheendofthefile・Infact,inC,apairofbraces({})identifiesthescopeofavariable・Whendefiningafunction,youmusthaveapairofbraces,andtherangeofvariablesd
6、efinedinthatscopestartsfromthevariabledefinitiontotheendofthescope,thatis,totherightbrace・Compoundstatementsaremadeupofstatementsandapairofbraces,whicharealsoscopedtobraces.Variablesdefinedwithinacompositestatementcanalsobeusedonlywithinthecompoundstatement,w
7、hichisconsideredanundefinedsymbol(undefined,symbo1).Inaddition,apairofbracesfollowedbytheifstatement,theswitchstatement,theforstatement,andsoon.Scopescanbenested,thatis,theycanhaveanynumberofscopeswithinascope,forexample:Int,main()Int,a,B,c;Float,a,b;C二a*b;Th
8、eintegervariablesa,B,andCdefinedatthebeginningofthemainfunctionstartfromtheirdefinitionstotheendofthemainfunction.Integervariablesa,B,andCarealsousedwithinthescopeofthefunction(thatis,the