亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? chapter4.html

?? C programming language. An excellent book on C programming. Recommended to C beginner.
?? HTML
?? 第 1 頁 / 共 4 頁
字號:
<strong>Exercise 4-5.</strong> Add access to library functions like<tt>sin</tt>, <tt>exp</tt>, and <tt>pow</tt>. See </tt>&lt;math.h&gt;</tt> in<a href="appb.html#sb.4">Appendix B, Section 4</a>.<p><strong>Exercise 4-6.</strong> Add commands for handling variables. (It'seasy to provide twenty-six variables with single-letter names.) Add avariable for the most recently printed value.<p><strong>Exercise 4-7.</strong> Write a routine <tt>ungets(s)</tt> that willpush back an entire string onto the input. Should <tt>ungets</tt> know about<tt>buf</tt> and <tt>bufp</tt>, or should it just use <tt>ungetch</tt>?<p><strong>Exercise 4-8.</strong> Suppose that there will never be more than onecharacter of pushback. Modify <tt>getch</tt> and <tt>ungetch</tt>accordingly.<p><strong>Exercise 4-9.</strong> Our <tt>getch</tt> and <tt>ungetch</tt> do nothandle a pushed-back <tt>EOF</tt> correctly. Decide what their propertiesought to be if an <tt>EOF</tt> is pushed back, then implement your design.<p><strong>Exercise 4-10.</strong> An alternate organization uses<tt>getline</tt> to read an entire input line; this makes <tt>getch</tt> and<tt>ungetch</tt> unnecessary. Revise the calculator to use this approach.<h2><a name="s4.4">4.4 Scope Rules</a></h2>The functions and external variables that make up a C program need not allbe compiled at the same time; the source text of the program may be kept inseveral files, and previously compiled routines may be loaded from libraries.Among the questions of interest are<ul><li>How are declarations written so that variables are properly declared    during compilation?<li>How are declarations arranged so that all the pieces will be properly    connected when the program is loaded?<li>How are declarations organized so there is only one copy?<li>How are external variables initialized?</ul>Let us discuss these topics by reorganizing the calculator program intoseveral files. As a practical matter, the calculator is too small to be worthsplitting, but it is a fine illustration of the issues that arise in largerprograms.<p>The <em>scope</em> of a name is the part of the program within which the namecan be used. For an automatic variable declared at the beginning of a function,the scope is the function in which the name is declared. Local variables ofthe same name in different functions are unrelated. The same is true of theparameters of the function, which are in effect local variables.<p>The scope of an external variable or a function lasts from the point atwhich it is declared to the end of the file being compiled. For example,if <tt>main</tt>, <tt>sp</tt>, <tt>val</tt>, <tt>push</tt>, and<tt>pop</tt> are defined in one file, in the order shown above, that is,<pre>   main() { ... }   int sp = 0;   double val[MAXVAL];   void push(double f) { ... }   double pop(void) { ... }</pre>then the variables <tt>sp</tt> and <tt>val</tt> may be used in <tt>push</tt>and <tt>pop</tt> simply by naming them; no further declarations are needed.But these names are not visible in <tt>main</tt>, nor are <tt>push</tt> and<tt>pop</tt> themselves.<p>On the other hand, if an external variable is to be referred to before it isdefined, or if it is defined in a different source file from the one where itis being used, then an <tt>extern</tt> declaration is mandatory.<p>It is important to distinguish between the <em>declaration</em> of an externalvariable and its <em>definition</em>. A declaration announces the propertiesof a variable (primarily its type); a definition also causes storage to beset aside. If the lines<pre>   int sp;   double val[MAXVAL];</pre>appear outside of any function, they <em>define</em> the external variables<tt>sp</tt> and <tt>val</tt>, cause storage to be set aside, and also serve as thedeclarations for the rest of that source file. On the other hand, the lines<pre>   extern int sp;   extern double val[];</pre><em>declare</em> for the rest of the source file that <tt>sp</tt> is an <tt>int</tt>and that <tt>val</tt> is a <tt>double</tt> array (whose size is determinedelsewhere), but they do not create the variables or reserve storage for them.<p>There must be only one <em>definition</em> of an external variable among all thefiles that make up the source program; other files may contain <tt>extern</tt>declarations to access it. (There may also be <tt>extern</tt> declarations inthe file containing the definition.) Array sizes must be specified with thedefinition, but are optional with an <tt>extern</tt> declaration.<p>Initialization of an external variable goes only with the definition.<p>Although it is not a likely organization for this program, the functions<tt>push</tt> and <tt>pop</tt> could be defined in one file, and the variables<tt>val</tt> and <tt>sp</tt> defined and initialized in another. Then thesedefinitions and declarations would be necessary to tie them together:<p>&nbsp;&nbsp;<em>in file1</em>:<pre>      extern int sp;      extern double val[];      void push(double f) { ... }      double pop(void) { ... }</pre>&nbsp;&nbsp;<em>in file2</em>:<pre>      int sp = 0;      double val[MAXVAL];</pre>Because the <tt>extern</tt> declarations in <em>file1</em> lie ahead of and outsidethe function definitions, they apply to all functions; one set of declarationssuffices for all of <em>file1</em>. This same organization would also bee neededif the definition of <tt>sp</tt> and <tt>val</tt> followed their use in one file.<h2><a name="s4.5">4.5 Header Files</a></h2>Let is now consider dividing the calculator program into several sourcefiles, as it might be is each of the components were substantially bigger.The <tt>main</tt> function would go in one file, which we will call<tt>main.c</tt>; <tt>push</tt>, <tt>pop</tt>, and their variables go into asecond file, <tt>stack.c</tt>; <tt>getop</tt> goes into a third,<tt>getop.c</tt>. Finally, <tt>getch</tt> and <tt>ungetch</tt> go into afourth file, <tt>getch.c</tt>; we separate them from the others because theywould come from a separately-compiled library in a realistic program.<p>There is one more thing to worry about - the definitions and declarationsshared among files. As much as possible, we want to centralize this, so thatthere is only one copy to get and keep right as the program evolves.Accordingly, we will place this common material in a <em>header file</em>,<tt>calc.h</tt>, which will be included as necessary. (The <tt>#include</tt>line is described in <a href="#s4.11">Section 4.11</a>.) The resulting programthen looks like this:<p><img src="pic41.gif"><p>There is a tradeoff between the desire that each file have access only to theinformation it needs for its job and the practical reality that it is harderto maintain more header files. Up to some moderate program size, it isprobably best to have one header file that contains everything that is to beshared between any two parts of the program; that is the decision we madehere. For a much larger program, more organization and more headers would beneeded.<h2><a name="s4.6">4.6 Static Variables</a></h2>The variables <tt>sp</tt> and <tt>val</tt> in <tt>stack.c</tt>, and <tt>buf</tt> and<tt>bufp</tt> in <tt>getch.c</tt>, are for the private use of the functions in theirrespective source files, and are not meant to be accessed by anything else. The<tt>static</tt> declaration, applied to an external variable or function, limitsthe scope of that object to the rest of the source file being compiled.External <tt>static</tt> thus provides a way to hide names like <tt>buf</tt> and<tt>bufp</tt> in the <tt>getch-ungetch</tt> combination, which must be external so theycan be shared, yet which should not be visible to users of <tt>getch</tt> and<tt>ungetch</tt>.<p>Static storage is specified by prefixing the normal declaration with the word<tt>static</tt>. If the two routines and the two variables are compiled in onefile, as in<pre>   static char buf[BUFSIZE];  /* buffer for ungetch */   static int bufp = 0;       /* next free position in buf */   int getch(void) { ... }   void ungetch(int c) { ... }</pre>then no other routine will be able to access <tt>buf</tt> and <tt>bufp</tt>, andthose names will not conflict with the same names in other files of the sameprogram. In the same way, the variables that <tt>push</tt> and <tt>pop</tt> use forstack manipulation can be hidden, by declaring <tt>sp</tt> and <tt>val</tt> to be<tt>static</tt>.<p>The external <tt>static</tt> declaration is most often used for variables,but it can be applied to functions as well. Normally, function names areglobal, visible to any part of the entire program. If a function is declared<tt>static</tt>, however, its name is  invisible outside of the file in whichit is declared.<p>The <tt>static</tt> declaration can also be applied to internal variables.Internal <tt>static</tt> variables are local to a particular function just asautomatic variables are, but unlike automatics, they remain in existencerather than coming and going each time the function is activated. This meansthat internal <tt>static</tt> variables provide private, permanent storagewithin a single function.<p><strong>Exercise 4-11.</strong> Modify <tt>getop</tt> so that it doesn't need to use<tt>ungetch</tt>. Hint: use an internal <tt>static</tt> variable.<h2><a name="s4.7">4.7 Register Variables</a></h2>A <tt>register</tt> declaration advises the compiler that the variable inquestion will be heavily used. The idea is that <tt>register</tt> variables areto be placed in machine registers, which may result in smaller and fasterprograms. But compilers are free to ignore the advice.<p>The <tt>register</tt> declaration looks like<pre>   register int  x;   register char c;</pre>and so on. The <tt>register</tt> declaration can only be applied to automaticvariables and to the formal parameters of a function. In this later case, itlooks like<pre>   f(register unsigned m, register long n)   {       register int i;       ...   }</pre>In practice, there are restrictions on register variables, reflecting therealities of underlying hardware. Only a few variables in each function maybe kept in registers, and only certain types are allowed. Excess registerdeclarations are harmless, however, since the word <tt>register</tt> isignored for excess or disallowed declarations. And it is not possible to takethe address of a register variable (a topic covered in <ahref="chapter5.html">Chapter 5</a>), regardless of whether the variable isactually placed in a register. The specific restrictions on number and typesof register variables vary from machine to machine.<h2><a name="s4.8">4.8 Block Structure</a></h2>C is not a block-structured language in the sense of Pascal or similarlanguages, because functions may not be defined within other functions. Onthe other hand, variables can be defined in a block-structured fashion withina function. Declarations of variables (including initializations) may followthe left brace that introduces <em>any</em> compound statement, not just theone that begins a function. Variables declared in this way hide anyidentically named variables in outer blocks, and remain in existence untilthe matching right brace. For example, in<pre>   if (n > 0) {       int i;  /* declare a new i */       for (i = 0; i &lt; n; i++)           ...   }</pre>the scope of the variable <tt>i</tt> is the ``true'' branch of the<tt>if</tt>; this <tt>i</tt> is unrelated to any <tt>i</tt> outside theblock. An automatic variable declared and initialized in a block isinitialized each time the block is entered.<p>Automatic variables, including formal parameters, also hide external variablesand functions of the same name. Given the declarations<pre>   int x;   int y;   f(double x)   {       double y;   }</pre>then within the function <tt>f</tt>, occurrences of <tt>x</tt> refer to the parameter,which is a <tt>double</tt>; outside <tt>f</tt>, they refer to the external <tt>int</tt>.The same is true of the variable <tt>y</tt>.<p>As a matter of style, it's best to avoid variable names that conceal names inan outer scope; the potential for confusion and error is too great.<h2><a name="s4.9">4.9 Initialization</a></h2>Initialization has been mentioned in passing many times so far, but alwaysperipherally to some other topic. This section summarizes some of the rules,now that we have discussed the various storage classes.<p>In the absence of explicit initialization, external and static variables areguaranteed to be initialized to zero; automatic and register variables haveundefined (i.e., garbage) initial values.<p>Scalar variables may be initialized when they are defined, by following thename with an equals sign and an expression:<pre>   int x = 1;   char squota = '\'';   long day = 1000L * 60L * 60L * 24L; /* milliseconds/day */</pre>For external and static variables, the initializer must be a constantexpression; the initialization is done once, conceptionally before the programbegins execution. For automatic and register variables, the initializer is notrestricted to being a constant: it may be any expression involving previouslydefined values, even function calls. For example, the initialization of thebinary search program in <a href="chapter3.html#s3.3">Section 3.3</a> couldbe written as<pre>   int binsearch(int x, int v[], int n)   {       int low = 0;       int high = n - 1;       int mid;       ...   }</pre>instead of<pre>       int low, high, mid;       low = 0;       high = n - 1;</pre>In effect, initialization of automatic variables are just shorthand forassignment statements. Which form to prefer is largely a matter of taste. Wehave generally used explicit assignments, because initializers indeclarations are harder to see and further away from the point of use.<p>An array may be initialized by following its declaration with a list ofinitializers enclosed in braces and separated by commas. For example, toinitialize an array <tt>days</tt> with the number of days in each month:<pre>   int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }</pre>When the size of the array is omitted, the compiler will compute the length bycounting the initializers, of which there are 12 in this case.<p>If there are fewer initializers for an array than the specified size, theothers will be zero for external, static and automatic variables. It is anerror to have too many initializers. There is no way to specify repetitionof an initializer, nor to initialize an element in the middle of an array

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美日韩一区高清| 欧美综合视频在线观看| 日本一不卡视频| 免费观看在线综合色| 香蕉影视欧美成人| 奇米色777欧美一区二区| 日本女优在线视频一区二区| 日韩高清在线不卡| 国产一区二区三区精品欧美日韩一区二区三区 | 久久综合色婷婷| 日韩精品最新网址| 久久综合九色综合欧美98| 久久久久久日产精品| 国产精品国产三级国产aⅴ原创 | 色狠狠一区二区三区香蕉| 一本色道久久综合精品竹菊| 在线观看国产日韩| 欧美成人三级在线| 亚洲欧洲三级电影| 亚洲高清视频的网址| 久久国产欧美日韩精品| 成人在线视频首页| 欧美主播一区二区三区| 欧美大白屁股肥臀xxxxxx| 国产网站一区二区| 亚洲激情图片qvod| 裸体健美xxxx欧美裸体表演| 国产成人免费av在线| 国产精品青草久久| 中文字幕亚洲视频| 久久久www成人免费毛片麻豆| 国产精品久久久久久久久免费丝袜 | 成人美女视频在线观看18| 久久免费精品国产久精品久久久久 | 国产乱码字幕精品高清av| 日韩一区二区在线观看| 美日韩一区二区| 日韩欧美在线影院| 九九久久精品视频| 中文子幕无线码一区tr| 国产精品一线二线三线精华| 亚洲国产精品高清| 91美女片黄在线观看91美女| 亚洲欧洲精品一区二区精品久久久| 成人高清伦理免费影院在线观看| 日韩一区有码在线| 欧美亚日韩国产aⅴ精品中极品| 亚洲国产精品视频| 日韩欧美国产wwwww| 国产成人啪午夜精品网站男同| 国产日韩欧美精品一区| 色综合久久久久久久久| 婷婷六月综合网| 欧美电视剧在线看免费| 成人综合婷婷国产精品久久蜜臀| 中文字幕在线观看不卡视频| 欧美日韩免费高清一区色橹橹| 日韩国产高清影视| 日本一区二区视频在线观看| 色哟哟在线观看一区二区三区| 亚洲第一狼人社区| 国产区在线观看成人精品| 99国产精品国产精品久久| 亚洲一区二区视频| 2014亚洲片线观看视频免费| av在线免费不卡| 无码av免费一区二区三区试看| 2021久久国产精品不只是精品 | 国产尤物一区二区在线| 亚洲欧美激情视频在线观看一区二区三区| 日本丰满少妇一区二区三区| 喷白浆一区二区| 最近日韩中文字幕| 欧美一卡2卡3卡4卡| a亚洲天堂av| 久久精品国产第一区二区三区| 亚洲自拍偷拍av| 久久精品欧美一区二区三区麻豆| 欧美在线视频你懂得| 大桥未久av一区二区三区中文| 亚洲成人三级小说| 综合av第一页| 久久久午夜精品理论片中文字幕| 欧美性一级生活| 成人动漫中文字幕| 精品夜夜嗨av一区二区三区| 亚洲一区二区视频在线| 中文字幕巨乱亚洲| 26uuu色噜噜精品一区| 欧美日韩的一区二区| 91视频精品在这里| 大陆成人av片| 国产精品456| 久久精品国产在热久久| 亚洲一区二区高清| 亚洲精品国产品国语在线app| 日本一区二区在线不卡| 久久亚区不卡日本| 欧美一区二区三区影视| 欧美精品乱人伦久久久久久| 91免费国产在线| 成人精品视频网站| 丁香五精品蜜臀久久久久99网站| 国产在线视频一区二区| 久久精品国产第一区二区三区| 午夜精品在线看| 亚洲一区视频在线| 亚洲午夜精品一区二区三区他趣| **欧美大码日韩| 中文字幕一区二区5566日韩| 国产精品高潮呻吟久久| 中文字幕av一区 二区| 国产精品午夜春色av| 日本一区二区免费在线观看视频| 久久免费视频一区| 日本一区二区三区免费乱视频| 国产亚洲一区二区三区| 久久久久9999亚洲精品| 一区二区三区毛片| 亚洲欧美国产77777| 亚洲欧美电影院| 亚洲图片自拍偷拍| 男女男精品视频| 狠狠色丁香婷婷综合| 国产91精品一区二区麻豆亚洲| 粉嫩一区二区三区性色av| 成人国产视频在线观看| 色综合天天综合狠狠| 在线精品观看国产| 欧美精品日韩一本| 久久午夜免费电影| 国产精品美女久久久久aⅴ | 日本精品裸体写真集在线观看 | 成人av电影在线网| 欧美亚洲国产bt| 精品久久人人做人人爱| 国产精品天干天干在线综合| 亚洲免费在线观看视频| 亚洲成人av一区二区| 久久国产尿小便嘘嘘| 国产精品77777竹菊影视小说| www.日韩大片| 69成人精品免费视频| 国产亚洲欧美日韩在线一区| 亚洲精品综合在线| 老色鬼精品视频在线观看播放| 岛国一区二区在线观看| 欧美日韩高清在线播放| 26uuu国产日韩综合| 一区二区免费在线| 精品一区二区三区在线观看| 91日韩精品一区| 日韩欧美另类在线| 国产精品福利电影一区二区三区四区| 一区二区三区小说| 国产久卡久卡久卡久卡视频精品| 91在线视频播放| 精品久久一区二区三区| 蜜桃精品视频在线观看| av在线一区二区| 精品国产电影一区二区| 亚洲一区二区欧美激情| 高清成人在线观看| 欧美一区午夜视频在线观看| 18涩涩午夜精品.www| 久久国产精品99精品国产| 日本精品免费观看高清观看| 国产三级欧美三级日产三级99| 亚洲网友自拍偷拍| 99国产麻豆精品| 国产欧美日韩精品在线| 久久精品国产成人一区二区三区| 色播五月激情综合网| 国产精品网站在线播放| 韩国午夜理伦三级不卡影院| 欧美久久久久久久久久| 亚洲视频一二区| 成人福利视频网站| 久久噜噜亚洲综合| 国产综合色在线| 日韩欧美自拍偷拍| 丝袜亚洲精品中文字幕一区| 色av一区二区| 亚洲黄色尤物视频| 91丨porny丨最新| 国产精品福利av| 波多野结衣一区二区三区| 久久品道一品道久久精品| 久久91精品久久久久久秒播| 欧美一区二区免费| 日韩精品欧美精品| 欧美一级免费大片| 日产精品久久久久久久性色| 欧美日韩在线亚洲一区蜜芽| 亚洲宅男天堂在线观看无病毒| 91黄色免费观看| 亚洲国产精品一区二区尤物区| 欧美性生活一区| 天天综合色天天| 91麻豆精品国产91久久久久|