日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

c语言存储类_C编程语言的存储类

發布時間:2025/3/11 编程问答 12 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言存储类_C编程语言的存储类 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

c語言存儲類

A variable's storage class tells us the following,

變量的存儲類告訴我們以下內容:

  • Where the variables would be stored?

    變量將存儲在哪里?

  • What will be the initial of the variable, if the initial value is not specifically assigned? (i.e. the default initial value).

    如果未特別指定初始值,則變量的初始值是什么? (即默認初始值)。

  • What is the scope of the variables, i.e. in which part of the program of the functions the value of the variable would be available?

    變量的范圍是什么,即變量的值在函數程序的哪個部分可用?

  • What is the life of the variable, i.e. how long the variable exists?

    變量的壽命是多少,即變量存在多長時間?

  • C中的存儲類類型 (Types of storage classes in C)

    There are four classes in C programming language,

    C編程語言共有四類,

  • Automatic storage classes

    自動存儲類

  • Register storage classes

    注冊存儲類別

  • Static storage classes

    靜態存儲類

  • External storage classes

    外部存儲類別

  • 1)自動存儲類 (1) Automatic storage classes)

    The keyword auto is used to declare variable of automatic storage class. (keyword auto is optional).

    關鍵字auto用于聲明自動存儲類的變量。 (關鍵字auto是可選的)。

    Syntax

    句法

    auto int a;int a; StorageMemory
    Default initial valueUnpredictable value
    ScopeLocal to the block in which the variable is defined.
    LifeControl remains within the block in which the variable is defined.
    存儲 記憶
    默認初始值 不可預測的價值
    范圍 局部于定義變量的塊。
    生活 控制保留在定義變量的塊內。

    Example: To display the default values

    示例:顯示默認值

    #include <stdio.h>int main () {auto int i,j;printf("\n%d %d",i,j);return 0; }

    NOTE: In the output two garbage values will be displayed as automatic variable by default store garbage values.

    注意:在輸出中,默認情況下,存儲垃圾值將顯示兩個垃圾值作為自動變量。

    .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}} .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}}

    2)注冊存儲類 (2) Register storage classes)

    The keyword register is used to declare a variable of the register storage class.

    關鍵字register用于聲明寄存器存儲類的變量。

    Syntax

    句法

    register int a; Storage CPU Register
    Default initial valueGarbage value
    Scope Local to the block in which the variable is defined.
    LifeControl remains within the block in which the variable is defined.
    存儲 CPU寄存器
    默認初始值 垃圾價值
    范圍 局部于定義變量的塊。
    生活 控制保留在定義變量的塊內。

    Example:

    例:

    #include <stdio.h>int main() {register int i;for(i=1;i<=100;i++);printf("%d",i);return 0; }

    Output

    輸出量

    101

    NOTE: A variable stored in CPU register can always be accessed faster than the one which is stored in memory.

    注意:存儲在CPU寄存器中的變量始終可以比存儲在存儲器中的變量更快地訪問。

    We cannot use register storage class for all types of variables.

    我們不能將寄存器存儲類用于所有類型的變量。

    Example: register double a; ,register float c; etc.

    示例:注冊double a; ,注冊float c; 等等

    3)靜態存儲類 (3) Static storage classes)

    The keyword static is used to declare variables of static storage class.

    關鍵字static用于聲明靜態存儲類的變量。

    Syntax

    句法

    static int i; Storage Memory
    Default initial value0
    Scope Local to the block in which the variable is defined.
    LifeValue of the variable remains b/w different function calls.
    存儲 記憶
    默認初始值 0
    范圍 局部于定義變量的塊。
    生活 變量的值仍然是黑白不同的函數調用。

    Example:

    例:

    #include <stdio.h>void abc() {static int a=10;printf("%d\n",a);a=a+10; }int main() {abc();abc();abc(); }

    Output

    輸出量

    102030

    NOTE: We should avoid using static variables unless we really need them. Because their value are kept in memory when the variables are not active, which means they take up space in memory that could otherwise be used by other variables.

    注意:我們應該避免使用靜態變量,除非我們確實需要它們。 因為當變量不活動時它們的值會保留在內存中,這意味著它們會占用內存中的空間,否則這些空間可能會被其他變量使用。

    .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}} .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}}

    4)外部存儲類 (4) External storage classes)

    The keyword extern is used to declare the variables of external storage class.

    關鍵字extern用于聲明外部存儲類的變量。

    In this the variable declared without keyword but it should be defined above the function(outside).

    在這種情況下,聲明為不帶關鍵字的變量,但應在函數(外部)上方定義。

    Syntax

    句法

    extern int i; Storage Memory
    Default initial value0
    Scope Global
    LifeAs long as the program execution does not come to an end.
    存儲 記憶
    默認初始值 0
    范圍 全球
    生活 只要程序執行沒有結束。

    Example:

    例:

    #include <stdio.h>/*Global variable*/ int a=10; void abc() {printf("%d\n",a);a=a+10; }int main() {a=a+5;printf("%d\n",a);a=a+20;abc();printf("%d\n",a);abc();a=a+20;abc();printf("%d\n",a);return 0; }

    Output

    輸出量

    153545457585

    NOTE: Mostly in many cases preference is given to a local variable.

    注意:通常在許多情況下,優先級是局部變量。

    翻譯自: https://www.includehelp.com/c/storage-classes.aspx

    c語言存儲類

    總結

    以上是生活随笔為你收集整理的c语言存储类_C编程语言的存储类的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。