c语言中,#define local 是什么意思

Python015

c语言中,#define local 是什么意思,第1张

#define是宏定义的意思,宏定义是用宏名来表示一个字符串,在宏展开时又以该字符串取代宏名,这只是一种简单的代换,字符串中可以含任何字符,可以是常数,也可以是表达式,预处理程序对它不作任何检查。如有错误,只能在编译已被宏展开后的源程序时发现。

你可以在局部程序块中说明一些变量,这种变量被称为局部变量,它们只能在局部程序块的开始部分说明,并且只在说明它的局部程序块中有效。

如果局部变量与局部程序块以外的变量重名,则前者优先于后者。

下面是一个使用局部程序块的例子:

#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)

}