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

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

?? chapter4.html

?? C programming language. An excellent book on C programming. Recommended to C beginner.
?? HTML
?? 第 1 頁 / 共 4 頁
字號:
   int atoi(char s[])   {       double atof(char s[]);       return (int) atof(s);   }</pre>Notice the structure of the declarations and the return statement. The valueof the expression in<pre>   return <em>expression</em>;</pre>is converted to the type of the function before the return is taken.Therefore, the value of <tt>atof</tt>, a <tt>double</tt>, is convertedautomatically to <tt>int</tt> when it appears in this <tt>return</tt>, sincethe function <tt>atoi</tt> returns an <tt>int</tt>. This operation doespotentionally discard information, however, so some compilers warn of it. Thecast states explicitly that the operation is intended, and suppresses anywarning.<p><strong>Exercise 4-2.</strong> Extend <tt>atof</tt> to handle scientificnotation of the form<pre>   123.45e-6</pre>where a floating-point number may be followed by <tt>e</tt> or <tt>E</tt> andan optionally signed exponent.<h2><a name="s4.3">4.3 External Variables</a></h2>A C program consists of a set of external objects, which are either variablesor functions. The adjective ``external'' is used in contrast to ``internal'',which describes the arguments and variables defined inside functions. Externalvariables are defined outside of any function, and are thus potentionallyavailable to many functions. Functions themselves are always external, becauseC does not allow functions to be defined inside other functions. By default,external variables and functions have the property that all references to themby the same name, even from functions compiled separately, are references tothe same thing. (The standard calls this property <em>external linkage</em>.)In this sense, external variables are analogous to Fortran COMMON blocks orvariables in the outermost block in Pascal. We will see later how to defineexternal variables and functions that are visible only within a single sourcefile.Because external variables are globally accessible, they provide an alternativeto function arguments and return values for communicating data betweenfunctions. Any function may access an external variable by referring to it byname, if the name has been declared somehow.<p>If a large number of variables must be shared among functions, externalvariables are more convenient and efficient than long argument lists. Aspointed out in <a href="chapter1.html">Chapter 1</a>, however, this reasoning should beapplied with some caution, for it can have a bad effect on program structure,and lead to programs with too many data connections between functions.<p>External variables are also useful because of their greater scope and lifetime.Automatic variables are internal  to a function; they come into existence whenthe function is entered, and disappear when it is left. External variables, onthe other hand, are permanent, so they can retain values from one functioninvocation to the next. Thus if two functions must share some data, yetneither calls the other, it is often most convenient if the shared data iskept in external variables rather than being passed in and out via arguments.<p>Let us examine this issue with a larger example. The problem is to write acalculator program that provides the operators <tt>+</tt>, <tt>-</tt>, <tt>*</tt>and <tt>/</tt>. Because it is easier to implement, the calculator will use reversePolish notation instead of infix. (Reverse Polish notation is used by somepocket calculators, and in languages like Forth and Postscript.)<p>In reverse Polish notation, each operator follows its operands; an infixexpression like<pre>   (1 - 2) * (4 + 5)</pre>is entered as<pre>   1 2 - 4 5 + *</pre>Parentheses are not needed; the notation is unambiguous as long as we knowhow many operands each operator expects.<p>The implementation is simple. Each operand is pushed onto a stack; when anoperator arrives, the proper number of operands (two for binary operators)is popped, the operator is applied to them, and the result is pushed backonto the stack. In the example above, for instance, 1 and 2 are pushed, thenreplaced by their difference, -1. Next, 4 and 5 are pushed and then replacedby their sum, 9. The product of -1 and 9, which is -9, replaces them onthe stack. The value on the top of the stack is popped and printed when theend of the input line is encountered.<p>The structure of the program is thus a loop that performs the proper operationon each operator and operand as it appears:<pre>   while (<em>next operator or operand is not end-of-file indicator</em>)       if (<em>number</em>)           <em>push it</em>       else if (<em>operator</em>)           <em>pop operands</em>           <em>do operation</em>           <em>push result</em>       else if (<em>newline</em>)           <em>pop and print top of stack</em>       else           <em>error</em></pre>The operation of pushing and popping a stack are trivial, but by the time errordetection and recovery are added, they are long enough that it is better toput each in a separate function than to repeat the code throughout the wholeprogram. And there should be a separate function for fetching the next inputoperator or operand.<p>The main design decision that has not yet been discussed is where the stack is,that is, which routines access it directly. On possibility is to  keep it in<tt>main</tt>, and pass the stack and the current stack position to the routinesthat push and pop it. But <tt>main</tt> doesn't need to know about the variablesthat control the stack; it only does push and pop operations. So we havedecided to store the stack and its associated information in external variablesaccessible to the <tt>push</tt> and <tt>pop</tt> functions but not to <tt>main</tt>.<p>Translating this outline into code is easy enough. If for now we think of theprogram as existing in one source file, it will look like this:<p>&nbsp;&nbsp;&nbsp;&nbsp;<tt>#include</tt><em>s</em><br>&nbsp;&nbsp;&nbsp;&nbsp;<tt>#define</tt><em>s</em><p>&nbsp;&nbsp;&nbsp;&nbsp;<em>function declarations for</em> <tt>main</tt><p>&nbsp;&nbsp;&nbsp;&nbsp;<tt>main() { ... }</tt><p>&nbsp;&nbsp;&nbsp;&nbsp;<em>external variables for</em> <tt>push</tt> <em>and</em> <tt>pop</tt><pre>   void push( double f) { ... }   double pop(void) { ... }   int getop(char s[]) { ... }</pre>&nbsp;&nbsp;&nbsp;&nbsp;<em>routines called by</em> <tt>getop</tt><p>Later we will discuss how this might be split into two or more source files.<p>The function <tt>main</tt> is a loop containing a big <tt>switch</tt> on the type ofoperator or operand; this is a more typical use of <tt>switch</tt> than the oneshown in <a href="chapter3.html#s3.4">Section 3.4</a>.<pre>   #include &lt;stdio.h&gt;   #include &lt;stdlib.h&gt;  /* for  atof() */   #define MAXOP   100  /* max size of operand or operator */   #define NUMBER  '0'  /* signal that a number was found */   int getop(char []);   void push(double);   double pop(void);   /* reverse Polish calculator */   main()   {       int type;       double op2;       char s[MAXOP];       while ((type = getop(s)) != EOF) {           switch (type) {           case NUMBER:               push(atof(s));               break;           case '+':               push(pop() + pop());               break;           case '*':               push(pop() * pop());               break;           case '-':               op2 = pop();               push(pop() - op2);               break;           case '/':               op2 = pop();               if (op2 != 0.0)                   push(pop() / op2);               else                   printf("error: zero divisor\n");               break;           case '\n':               printf("\t%.8g\n", pop());               break;           default:               printf("error: unknown command %s\n", s);               break;           }       }       return 0;   }</pre>Because <tt>+</tt> and <tt>*</tt> are commutative operators, the order in whichthe popped operands are combined is irrelevant, but for <tt>-</tt> and <tt>/</tt>the left and right operand must be distinguished. In<pre>   push(pop() - pop());   /* WRONG */</pre>the order in which the two calls of <tt>pop</tt> are evaluated is not defined.To guarantee the right order, it is necessary to pop the first value into atemporary variable as we did in <tt>main</tt>.<pre>   #define MAXVAL  100  /* maximum depth of val stack */   int sp = 0;          /* next free stack position */   double val[MAXVAL];  /* value stack */   /* push:  push f onto value stack */   void push(double f)   {       if (sp &lt; MAXVAL)           val[sp++] = f;       else           printf("error: stack full, can't push %g\n", f);   }   /* pop:  pop and return top value from stack */   double pop(void)   {       if (sp &gt; 0)           return val[--sp];       else {           printf("error: stack empty\n");           return 0.0;       }   }</pre>A variable is external if it is defined outside of any function. Thus thestack and stack index that must be shared by <tt>push</tt> and <tt>pop</tt>are defined outside these functions. But <tt>main</tt> itself does not referto the stack or stack position - the representation can be hidden.<p>Let us now turn to the implementation of <tt>getop</tt>, the function thatfetches the next operator or operand. The task is easy. Skip blanks and tabs.If the next character is not a digit or a hexadecimal point, return it.Otherwise, collect a string of digits (which might include a decimal point),and return <tt>NUMBER</tt>, the signal that a number has been collected.<pre>   #include &lt;ctype.h&gt;   int getch(void);   void ungetch(int);   /* getop:  get next character or numeric operand */   int getop(char s[])   {       int i, c;       while ((s[0] = c = getch()) == ' ' || c == '\t')           ;       s[1] = '\0';       if (!isdigit(c) && c != '.')           return c;      /* not a number */       i = 0;       if (isdigit(c))    /* collect integer part */           while (isdigit(s[++i] = c = getch()))              ;       if (c == '.')      /* collect fraction part */           while (isdigit(s[++i] = c = getch()))              ;       s[i] = '\0';       if (c != EOF)           ungetch(c);       return NUMBER;   }</pre>What are <tt>getch</tt> and <tt>ungetch</tt>? It is often the case that a programcannot determine that it has read enough input until it has read too much. Oneinstance is collecting characters that make up a number: until the firstnon-digit is seen, the number is not complete. But then the program has readone character too far, a character that it is not prepared for.<p>The problem would be solved if it were possible to ``un-read'' the unwantedcharacter. Then, every time the program reads one character too many, it couldpush it back on the input, so the rest of the code could behave as if it hadnever been read. Fortunately, it's easy to simulate un-getting a character, bywriting a pair of cooperating functions. <tt>getch</tt> delivers the next inputcharacter to be considered; <tt>ungetch</tt> will return them before reading newinput.<p>How they work together is simple. <tt>ungetch</tt> puts the pushed-backcharacters into a shared buffer -- a character array. <tt>getch</tt> readsfrom the buffer if there is anything else, and calls <tt>getchar</tt> if thebuffer is empty. There must also be an index variable that records theposition of the current character in the buffer.<p>Since the buffer and the index are shared by <tt>getch</tt> and <tt>ungetch</tt>and must retain their values between calls, they must be external to bothroutines. Thus we can write <tt>getch</tt>, <tt>ungetch</tt>, and their sharedvariables as:<pre>   #define BUFSIZE 100   char buf[BUFSIZE];    /* buffer for ungetch */   int bufp = 0;         /* next free position in buf */   int getch(void)  /* get a (possibly pushed-back) character */   {       return (bufp &gt; 0) ? buf[--bufp] : getchar();   }   void ungetch(int c)   /* push character back on input */   {       if (bufp &gt;= BUFSIZE)           printf("ungetch: too many characters\n");       else           buf[bufp++] = c;   }</pre>The standard library includes a function <tt>ungetch</tt> that provides onecharacter of pushback; we will discuss it in <a href="chapter7.html">Chapter 7</a>.We have used an array for the pushback, rather than a single character, toillustrate a more general approach.<p><strong>Exercise 4-3.</strong> Given the basic framework, it'sstraightforward to extend the calculator. Add the modulus (%) operator andprovisions for negative numbers.<p><strong>Exercise 4-4.</strong> Add the commands to print the top elements ofthe stack without popping, to duplicate it, and to swap the top two elements.Add a command to clear the stack.<p>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
激情亚洲综合在线| 欧美日高清视频| 欧美精品免费视频| 国产精品免费视频网站| 日韩—二三区免费观看av| 99在线精品免费| 久久亚洲精精品中文字幕早川悠里| 夜夜嗨av一区二区三区中文字幕 | 日韩精品在线一区二区| 亚洲黄色免费网站| 成人美女视频在线观看18| 欧美一区二区三区不卡| 一区二区高清在线| 91女厕偷拍女厕偷拍高清| 国产拍揄自揄精品视频麻豆| 热久久国产精品| 欧美理论片在线| 亚洲一二三四区不卡| 一本一道久久a久久精品 | 91碰在线视频| 国产精品系列在线| 成人精品在线视频观看| 精品乱人伦小说| 久久成人精品无人区| 91精品国产综合久久福利软件| 亚洲国产视频网站| 欧美性三三影院| 午夜精品久久久久| 欧美一区二区观看视频| 久久er精品视频| 精品久久一二三区| 国产一区不卡视频| 国产欧美一区二区精品性色 | 日韩理论片网站| www.亚洲色图.com| 亚洲视频每日更新| 91黄色免费观看| 亚洲国产精品一区二区www在线| 色婷婷综合久久久中文字幕| 亚洲综合免费观看高清完整版 | 日韩激情视频在线观看| 正在播放亚洲一区| 蜜臀av一级做a爰片久久| 日韩亚洲欧美一区二区三区| 精品一区二区久久久| 久久麻豆一区二区| 99久久99精品久久久久久| 亚洲精品免费电影| 欧美日本一区二区在线观看| 视频一区二区国产| 久久精品夜色噜噜亚洲aⅴ| hitomi一区二区三区精品| 亚洲午夜国产一区99re久久| 欧美一区二区三区日韩视频| 韩国欧美一区二区| 亚洲免费观看在线观看| 8v天堂国产在线一区二区| 国产一区二区三区黄视频 | 欧美美女黄视频| 精品一区二区免费看| 综合av第一页| 欧美成人vr18sexvr| gogogo免费视频观看亚洲一| 日日夜夜精品免费视频| 激情文学综合插| 亚洲精品在线观| 亚洲电影你懂得| 欧美日韩中字一区| 久久99精品国产麻豆婷婷洗澡| 国产欧美精品一区二区色综合| 日本精品免费观看高清观看| 免费久久99精品国产| 国产精品国产自产拍高清av| 欧美日韩高清一区二区| 国产69精品久久99不卡| 三级欧美韩日大片在线看| 亚洲国产精品成人综合色在线婷婷 | 67194成人在线观看| 9色porny自拍视频一区二区| 久久国产综合精品| 一区二区激情小说| 日本一区二区视频在线观看| 欧美一个色资源| 在线免费不卡电影| 国产91富婆露脸刺激对白| 激情五月婷婷综合网| 天堂成人国产精品一区| 亚洲裸体xxx| 国产精品你懂的在线欣赏| 日韩欧美综合在线| 欧美日韩久久久| 色综合久久久久久久久| 国产成人免费视频一区| 日韩电影免费在线看| 亚洲已满18点击进入久久| 中文字幕不卡在线| 国产人成亚洲第一网站在线播放 | 国产精品一区二区在线观看网站| 日韩精品一二区| 亚洲制服丝袜av| 亚洲日本成人在线观看| 亚洲欧美综合网| 国产精品天美传媒沈樵| 国产欧美va欧美不卡在线| 亚洲精品在线免费观看视频| 日韩欧美中文一区| 欧美一级欧美三级在线观看| 欧美一级欧美三级| 日韩精品一区二区三区视频| 欧美一区二区在线看| 91精品国产综合久久精品麻豆| 欧美网站大全在线观看| 欧美在线色视频| 欧美理论在线播放| 日韩免费看的电影| 久久综合色之久久综合| 久久综合久久综合久久综合| 久久久噜噜噜久久人人看 | 欧美大度的电影原声| 日韩精品一区二区三区中文精品| 欧美一区二区三区啪啪| 精品久久久影院| 国产午夜亚洲精品不卡| 国产网站一区二区| 国产精品美女一区二区| 亚洲欧美综合网| 亚洲国产欧美在线人成| 欧美96一区二区免费视频| 裸体一区二区三区| 国产成人综合在线播放| 99精品国产99久久久久久白柏 | 欧美精品一区二区三区蜜桃| 久久久久久久性| 综合自拍亚洲综合图不卡区| 亚洲午夜久久久久久久久电影网| 免费人成黄页网站在线一区二区| 激情综合网av| 97se亚洲国产综合自在线观| 欧美在线观看一二区| 日韩精品中文字幕一区二区三区 | 久久精品免视看| 亚洲精品久久久久久国产精华液| 午夜视频一区二区| 国产成人自拍网| 色94色欧美sute亚洲线路一久 | 国产精品一二二区| 91在线视频观看| 91精品国产aⅴ一区二区| 久久精品日产第一区二区三区高清版| 国产精品电影一区二区| 丝袜诱惑制服诱惑色一区在线观看 | 久久9热精品视频| 国产69精品一区二区亚洲孕妇| 在线精品视频免费观看| 欧美大肚乱孕交hd孕妇| 一区二区在线看| 狠狠色丁香久久婷婷综合_中| 日本韩国精品在线| 久久天天做天天爱综合色| 一区二区三区资源| 粉嫩av一区二区三区在线播放| 在线不卡a资源高清| 亚洲人成网站影音先锋播放| 久久成人免费电影| 欧美日韩一本到| 亚洲色图欧美激情| 国产成人综合网站| 日韩免费看的电影| 午夜久久电影网| 色综合色综合色综合色综合色综合| 欧美一级在线观看| 亚洲一二三区在线观看| a级精品国产片在线观看| 精品久久国产老人久久综合| 亚洲国产一二三| 91美女在线看| 国产精品麻豆99久久久久久| 国产一区二区三区在线观看免费| 欧美丰满少妇xxxxx高潮对白| 国产精品传媒入口麻豆| 国产一区二区三区免费在线观看| 欧美一区二区三区白人| 五月天中文字幕一区二区| 91国偷自产一区二区三区观看 | 欧美日韩亚洲综合| 亚洲男人的天堂av| 91免费视频网| 亚洲美女视频在线观看| 99久久精品免费观看| 中文字幕在线播放不卡一区| 国产成人综合在线观看| 久久久噜噜噜久久中文字幕色伊伊 | 中文字幕欧美三区| 国产伦精品一区二区三区视频青涩 | 欧美男男青年gay1069videost| 亚洲精品网站在线观看| 91在线视频网址| 亚洲在线视频免费观看| 欧美日韩一区二区在线观看| 婷婷开心久久网|