如果局部变量与局部程序块以外的变量重名,则前者优先于后者。
下面是一个使用局部程序块的例子:
#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)
}