如果局部变量与局部程序块以外的变量重名,则前者优先于后者。
下面是一个使用局部程序块的例子:
#include <stdio.h>
void main(void)
void main()
{
/ * Begin local block for function main() * /
int test_ var = 10
printf("Test variable before the if statement: %d\n", test_var)
if (test_var>5)
{
/ * Begin local block for "if" statement * /
int test_ var = 5
printf("Test variable within the if statement: %d\n",
test_var)
{
/ * Begin independent local block (not tied to
any function or keyword) * /
int test_var = 0
printf (
"Test variable within the independent local block: %d\n",
test_var)
}
/ * End independent local block * /
printf ("Test variable after the if statement: %d\n", test_var)
}
块指的是一块数据,是个抽象的概念,和C语言没有关系,这种抽象的东西,别说其他语言也能用,就是日常生活中也会把东西分块管理,C语言中没有对块进行定义,因为这只是个抽象的概念,块可以是内存块,数据块,程序块,哪怕是豆腐块也能是块。。。。。。意思就是在管理中被划分为一类的一个基本单位。。。