2016年12月21日 星期三

C 語言變數



韌體工程師 考題

  1. 何謂 全域變數 (Global Variable)
  2. 何謂 區域變數 (Local Variable)
  3. 何謂 靜態變數 (Static Variable)

/*
自動儲存區間與靜態儲存區間
*/

#include  <stdio.h>

int    fx = 0;                          /* 靜態儲存區間+檔案有效範圍 */

void func(void)
{
     static int       sx = 0;           /* 靜態儲存區間+資料段有效範圍 */
     int              ax = 0;           /* 自動儲存區間+資料段有效範圍 */


     printf("%3d%3d%3d\n", ax++, sx++, fx++);
}

int main(void)
{
    int    i;

    puts(" ax sx fx");
    puts("----------");
    for (i = 0; i < 10; i++)
        func();
    puts("----------");
 
    return (0);
}



參考出處:
明解C語言


關鍵字:
omgiraaaaonpo
pirhdln
ogetptd
otgistv

沒有留言:

張貼留言