在C数组的初始化 [英] Initialization of arrays in C

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

问题描述

在C,我已阅读,半初始化的阵列将被填充零的元素(不论整数或字符数组)的其余部分。

In C, I have read that half-initialized arrays will be filled with zeros for the rest of the elements (irrespective of integer or char arrays).

例如:

int arr[10] = {3};

改编[4] 将是0,如果初始化,如果没有初始化垃圾值。

arr[4] will be 0 if initialized and a junk value if not initialized.

我的问题是,将所有的C编译器上面的工作(或)本追加零可能发生或取决于编译器选项不会发生?我在code作曲家工作室(TI的IDE)的工作。我要确保这将适用于所有情况和所有的编译器工作。

My question is, will the above work for all C compilers (or) this appending of zeros might occur or not occur depending on the compiler option? I am working in Code composer studio (TI's IDE). I want to ensure that this will work for all cases and all compilers.

推荐答案

该行为是由C标准规定。但是,如果你担心你的编译器特定的行为,为什么不写一个测试?

The behaviour is specified by the C Standard. But if you are worried about the behaviour of your specific compiler, why not write a test?

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

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