C 變數如何作用域化
我們將在此看到 C 變數如何作用域化。C 中的變數始終是靜態作用域的。變數的繫結可由程式文字確定。這些都不依賴於執行時函式呼叫堆疊。
讓我們舉一個例子來了解這個概念。
示例
# include <stdio.h>
int x = 0;
int my_function() {
return x;
}
int my_function2() {
int x = 1;
return my_function();
}
int main(){
printf("The value is: %d\n", my_function2());
}輸出
The value is: 0
結果為 0。因為 my_function() 返回的值不依賴於呼叫該函式的函式。該函式始終返回全域性變數 x 的值。
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP