什么静态平均在ANSI-C [英] What does static mean in ANSI-C

查看:129
本文介绍了什么静态平均在ANSI-C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  什么“静态”的意味着在C程序?

什么是静态关键字用C呢?

我使用的是ANSI-C。我见过几个code例子,它们使用静态关键字变量前面和功能前面。什么是一个变量使用的情况下,目的是什么?什么是在一个函数中使用的情况下,目的是什么?

I'm using ANSI-C. I've seen in several code examples, they use the static keyword in front of variables and in front of functions. What is the purpose in case of using with a variable? And what is the purpose in case of using with a function?

推荐答案

正如一个简短的回答,有两种用法为静态关键字定义变量时:

Just as a brief answer, there are two usages for the static keyword when defining variables:

在文件范围内定义的静态关键字的即1变量。的定义之外的功能将只在该文件是可见的。任何企图从其它文件访问它们会导致在链接时尚未解决的符号。

1- Variables defined in the file scope with static keyword, i.e. defined outside functions will be visible only within that file. Any attempt to access them from other files will result in unresolved symbol at link time.

定义为静态块内部函数内将持续存在,或在同样的code座的不​​同调用生存2 - 变量。如果它们被定义初始化,则它们被初始化仅仅一次。 静态变量通常是保证被默认初始化为 0

2- Variables defined as static inside a block within a function will persist or "survive" across different invocations of the same code block. If they are defined initialized, then they are initialized only once. static variables are usually guaranteed to be initialized to 0 by default.

这篇关于什么静态平均在ANSI-C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆