c語言存儲類_C編程語言的存儲類

c語言存儲類

A variable's storage class tells us the following,

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

  1. Where the variables would be stored?

    變量將存儲在哪里?

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

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

  3. 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?

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

  4. 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編程語言共有四類,

  1. Automatic storage classes

    自動存儲類

  2. Register storage classes

    注冊存儲類別

  3. Static storage classes

    靜態存儲類

  4. 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.

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

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

輸出量

    10
20
30

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.

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

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

輸出量

    15
35
45
45
75
85

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

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

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

c語言存儲類

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/540811.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/540811.shtml
英文地址,請注明出處:http://en.pswp.cn/news/540811.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

jsonp請求html頁面,JavaScript中的JSON和JSONP

簡單地使用json并不能支持跨域資源請求&#xff0c;為了解決這個問題&#xff0c;需要采用jsonp數據交互協議。眾所周知&#xff0c;js文件的調用不受跨域與否的限制&#xff0c;因此如果想通過純web端跨域訪問數據&#xff0c;只能在遠程服務器上設法將json數據封裝進js格式的…

2017軟件工程實踐

課程信息 軟件工程實踐 參考教材 《構建之法》 作者&#xff1a;鄒欣&#xff0c; 編輯&#xff1a;周筠 他山之石 北京航空航天大學 羅杰&#xff0c; 劉乾 東北師范大學 楊貴福 北京電子科技學院 婁嘉鵬 教師&#xff1a;汪璟玢 助教&#xff1a;卞…

suse leap_Ruby程序檢查leap年

suse leapProblem statement: Given a year, we have to check whether it is a Leap year or not using Ruby program. 問題陳述 &#xff1a;給定年份&#xff0c;我們必須使用Ruby程序檢查是否為Le年。 Methods used: 使用的方法&#xff1a; gets(): This method is a pu…

html導航欄點擊不能跳轉,無法單擊導航欄中的鏈接CSS HTML

不確定是否允許您鏈接您的網站&#xff0c;但是如果允許。 因此&#xff0c;我可以將所有鏈接懸停在導航欄中&#xff0c;但我無法點擊它們&#xff0c;并且S的圖片是可移動的&#xff0c;但無法點擊&#xff0c;我做錯了什么&#xff1f;無法單擊導航欄中的鏈接CSS HTMLNickeb…

JAVA 取得當前目錄的路徑/Servlet/class/文件路徑/web路徑/url地址

2019獨角獸企業重金招聘Python工程師標準>>> 在寫Java程序時不可避免要獲取文件的路徑...總結一下,遺漏的隨時補上 1.可以在servlet的init方法里 String path getServletContext().getRealPath("/"); 這將獲取web項目的全路徑 例如 :E:\eclipseM9\worksp…

關于細分到字段的權限系統_操作系統中的細分

關于細分到字段的權限系統為什么需要細分&#xff1f; (Why Segmentation is required?) In the Operating System, an important drawback of memory management is the separation of the users view of memory and the actual physical memory. Paging is the scheme which…

計算機科學技術專業解析,專業解讀—計算機科學與技術

原標題&#xff1a;專業解讀—計算機科學與技術專業培養目標&#xff1a;本專業培養具有良好的科學素養&#xff0c;系統地、較好地掌握計算機科學與技術包括計算機硬件、軟件與應用的基本理論、基本知識和基本技能與方法&#xff0c;能在科研部門、教育單位、企業、事業、技術…

阿里云服務器配置開發環境第五章:Centos7.3切換為iptables防火墻

centos7.3默認使用的防火墻應該是firewall&#xff0c;而不是iptables。而我們xxmj服務器使用的是iptables防火墻。所以&#xff0c;在配置防火墻之前&#xff0c;我們需要先關閉firewall&#xff0c;安裝iptables。 1.關閉firewall service firewalld stop systemctl disable …

mba學什么書_MBA的完整形式是什么?

mba學什么書MBA&#xff1a;工商管理碩士 (MBA: Master of Business Administration) MBA is an abbreviation of a Master of Business Administration. It is a masters degree for post-graduation in business administration. This business masters degree program is a …

Qt for Android 開發大坑

Qt for Android 開發大坑 作者: qyvlik Qt 5.5.1 這里說一說比較常見的 Qt 開發安卓的大坑。希望同學們不要做無謂的掙扎&#xff0c;跳過這些坑。輸入框 首當其沖的是輸入框&#xff0c;Qt 的輸入在安卓上表現不佳. 無法支持安卓原生的輸入法訪問 Qt 的輸入框。就是安卓輸入法…

bca ac如何聯合索引_BCA的完整形式是什么?

bca ac如何聯合索引BCA&#xff1a;計算機應用學士學位 (BCA: Bachelor of Computer Applications) BCA is an abbreviation of Bachelor of Computer Applications. It is a three-year undergraduate program in Computer applications. It is considered equivalent to B.Te…

path r'c test.html',robot framework - robot命令參數解析

robot 命令參數解析version > 3.0.1原文檔查看命令:robot --helprobot -h-F --extension value通過文件擴展名控制需要執行的用例。如果只執行一個文件&#xff0c;這個參數無效。需要執行多個擴展名時&#xff0c;用“:”分隔開。Examples:--extension robot-F robot:txt-N…

嘿,程序員,你該學點經濟學了!

前言&#xff1a; 筆者一直認為&#xff0c;一個好的程序員&#xff0c;不僅僅是代碼敲得好&#xff0c;其它方面的知識和能力相同非常重要。特別是隨著年齡的增長。非常多人也慢慢的往管理層發展。這個時候溝通與協調能力變得更加重要&#xff0c;而一些策劃&#xff0c;推廣方…

linux硬件配置_Linux硬件配置

linux硬件配置What sort of hardware configuration is expected to run Linux? This is a decent question; the real hardware configuration for the OS changes intermittently. The Linux Hardware?HOWTO gives a (pretty much) complete posting of hardware supported…

重郵2019計算機考研復試名單,重慶郵電大學2019年碩士研究生招生復試通知

當前2019年考研分數線已經公布&#xff0c;穩穩過線的同學即可全心準備復試了&#xff0c;中公考研小編整理了“重慶郵電大學2019年碩士研究生招生復試通知”文章&#xff0c;希望對大家有所幫助!各復試考生&#xff1a;根據《2019年重慶郵電大學碩士研究生復試工作方案》&…

Linux相關圖解隨記

01.dns解析過程02.用戶訪問網站流程03.局域網電腦上網流程04.網站架構圖解轉載于:https://blog.51cto.com/qinbin/1954149

數據庫范式5nf_第五范式(5NF)| 數據庫管理系統

數據庫范式5nfFifth normal form (5NF) is also known as project-join normal form (PJ/NF). It is designed to minimize redundancy in relational databases by separating semantically connected relationships in multiple formats to store multi-valued facts. 第五范…

量子物理 詹班 計算機,(電氣系計算機系詹班)量子物理作業答案

西南交大峨眉校區大學物理西南交大峨眉校區《大學物理》(量子物理基礎)作業6(電氣、計算機、詹班)一 選擇題1. 以一定頻率的單色光照射在某種金屬上&#xff0c;測出其光電流曲線在圖中用實線表示&#xff0c;然后保持光的頻率不變&#xff0c;增大照射光的強度&#xff0c;測出…

MySQL5.6 新特性之GTID【轉】

轉自 MySQL5.6 新特性之GTID - jyzhou - 博客園http://www.cnblogs.com/zhoujinyi/p/4717951.html 背景&#xff1a; MySQL5.6在5.5的基礎上增加了一些改進&#xff0c;本文章先對其中一個一個比較大的改進"GTID"進行說明。 概念&#xff1a; GTID即全局事務ID&#…

python判斷素數程序_Python程序檢查素數

python判斷素數程序什么是質數&#xff1f; (What is a prime number?) A prime number is a natural number that is greater than 1 and cannot be formed by multiplying two smaller natural numbers. 質數是大于1的自然數&#xff0c;不能通過將兩個較小的自然數相乘而形…