静态数组 [英] static array

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

问题描述

嗨......我是c编程的新手....请解释一下我为什么要将一个字符数组声明为静态... $ x $ b eric

解决方案

di *** *******@yahoo.com 写道:


hi ...我是c编程新手....请解释我至于为什么要将一个字符数组声明为静态...比较... ... eric



在什么情况下?


相同的规则适用于任何其他变量的字符数组。


如果数组在编译单元中并且您不想要它是在其他地方可见的
,你声明它是静态的,以避免用数组的名称污染全局的

命名空间。


如果数组有函数范围并且你希望在调用之间保留值

,你会声明它是静态的。


-

Ian C. ollins。



di **** ******@yahoo.com 写道:


hi ...我是c编程新手....请解释我为为什么要将
一个字符数组声明为静态... thanx ... eric



在早些时候,也许在C99之前,本地数组不能初始化为
,除非它被声明为静态数据。


di ********** @ yahoo.com 写道:


嗨...我是c编程的新手....请解释一下为什么要将

一个字符数组声明为静态... thanx ... eric



一种可能性是您希望在后续调用函数期间记住该值

。这适用于所有类型的静态变量
而不仅仅是字符数组。另一种可能性

阅读7.5a和7.5b的FAQ。

http://c-faq.com/malloc/retaggr.html

Spiros Bousbouras


hi...i am new to c programming....please explain me as to why should
an character array be declared as static...thanx...eric

解决方案

di**********@yahoo.com wrote:

hi...i am new to c programming....please explain me as to why should
an character array be declared as static...thanx...eric

In what context?

The same rules apply for a character array as for any other variable.

If the array is in a compilation unit and you don''t want it to be
visible elsewhere, you declare it static to avoid polluting the global
namespace with the array''s name.

If the array has function scope and you wish the value to be retained
between calls, you would declare it static.

--
Ian Collins.



di**********@yahoo.com wrote:

hi...i am new to c programming....please explain me as to why should
an character array be declared as static...thanx...eric

In the earlier days, perhaps before C99, a local array could not be
initialized unless it was declared as a static one.


di**********@yahoo.com wrote:

hi...i am new to c programming....please explain me as to why should
an character array be declared as static...thanx...eric

One possibility is that you want the value to be remembered
during subsequent calls to the function. This applies to all kinds
of static variables not just character arrays. For another possibility
read 7.5a and 7.5b of the FAQ.

http://c-faq.com/malloc/retaggr.html

Spiros Bousbouras


这篇关于静态数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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