c语言中全局变量和静态变量_C语言中自动(自动)和静态变量之间的区别

C语言中,自动(auto)变量在每次函数调用时创建并销毁,而静态(static)变量只声明一次,程序执行结束后才销毁。静态变量不随函数调用而重新初始化,而自动变量每次调用都会初始化。
摘要由CSDN通过智能技术生成

c语言中全局变量和静态变量

Prerequisite: Storage classes in C

先决条件: C语言中的存储类

Automatic (auto) and static both are the keywords which are used under the storage classes, and they define the scope, lifetime, default value and memory segment of the variables.

自动( auto )和静态都是在存储类下使用的关键字,它们定义变量的范围,生存期,默认值和内存段。

1)自动('auto')变量 (1) Automatic (‘auto’) variable)

The all local variables which are defined within the function are known as auto (automatic) variables unless not specified i.e. by default a local variable is an auto variable. There is no need to put the keyword auto (it’s an optional) while declaring a local variable.

除非未指定,否则函数中定义的所有局部变量都称为自动 (自动)变量,即默认情况下,局部变量是自动变量。 在声明局部变量时,无需放置关键字auto (它是可选的)。

An auto variable created a new each time when the function (in which variable is declared) is called and destroyed when the program’s execution leaves the function.

每次调用函数(在其中声明变量)时都会创建一个新的自动变量,并在程序执行离开该函数时销毁该变量。 </

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值