部分初始化C中的数组默认值 [英] Partly initialized array default values in C

查看:99
本文介绍了部分初始化C中的数组默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于部分初始化数组的问题。我将给出一个代码示例:


int array [20] = {[10] = 55};


编译器吗给予我任何保证,其他价值(指数10除外)会有一些特殊价值吗?我读过,当使用C99时,其他值将为0,但如果我没有指定任何标准怎么办?

解决方案


您好,我有一个关于部分初始化数组的问题。我将给出一个代码示例:


int array [20] = {[10] = 55};


编译器吗给予我任何保证,其他价值(指数10除外)会有一些特殊价值吗?我读过,当使用C99时,其他值将为0,但如果我没有指定任何标准怎么办?



嗯?你是什​​么意思你没有指定任何标准?


如果你指定一个初始化者,即使它是空的(即{}),它会将未初始化的值默认为0或NULL(所有CPU上的NULL都不一定意味着0)。


Adrian


这是什么类型的代码? ?

展开 | 选择 | Wrap | 行号



嗯?你是什​​么意思你没有指定任何标准?

Adrian



我的意思是如果没有-std开关编译它


Hi, I have a question concerning partly initialized array. I''ll give an example of code:

int array[20] = {[10] = 55};

Does compiler grants me any assurance, that other values (except with index 10) will have some particular value? I''ve read, that when using C99, other values will be 0, but what if I don''t specify any standard?

解决方案

Hi, I have a question concerning partly initialized array. I''ll give an example of code:

int array[20] = {[10] = 55};

Does compiler grants me any assurance, that other values (except with index 10) will have some particular value? I''ve read, that when using C99, other values will be 0, but what if I don''t specify any standard?

Huh? What do you mean you don''t specify any standard?

If you specify an initialiser, even if it is empty (i.e. {}) it will default the uninitialised values to 0 or NULL (NULL doen''t necessarly mean 0 on all CPUs).


Adrian


What kind of code is this??

Expand|Select|Wrap|Line Numbers


Huh? What do you mean you don''t specify any standard?
Adrian

I meant if compile it without -std switch


这篇关于部分初始化C中的数组默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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