其他分享
首页 > 其他分享> > 不知道的地方(2)

不知道的地方(2)

作者:互联网

1.

int f(int a)
{
auto int b = 0;
static int c = 3;
b = b + 1;
c = c + 1;
return ( a + b + c );
}
int main()
{
int i,j;
i = f ( 2 );
j = f ( 2 );
printf("%d %d",i,j);
return 0;
}

输出i=7,j=8。

auto int定义的是局部变量,每次调用函数都会创建,static是静态全局变量,作用域是全局。

 

‍如果要一个变量在整个程序运行期间都存在,但是仅在说明它的函数内是可见的,则这个变量的存储类型应该被说明为( )。 

标签:return,变量,int,auto,地方,静态,static,知道
来源: https://www.cnblogs.com/whiteaki/p/15733622.html