数组初始化与{0},{0,}? [英] Array initialization with {0}, {0,}?

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

问题描述

说我要初始化myArray的

Say I want to initialize myArray

char myArray[MAX] = {0};  
char myArray[MAX] = {0,};  
char myArray[MAX]; memset(myArray, 0, MAX);  

他们都是等于或超过pferred任何其他$ P $?

Are they all equal or any preferred over another?

感谢您

推荐答案

它们等同关于产生code(至少在优化的版本),因为当一个数组与初始化{0} 语法,没有被明确指定为0被隐式初始化,编译器会知道足够插入到 memset的呼叫所有值。

They are equivalent regarding the generated code (at least in optimised builds) because when an array is initialised with {0} syntax, all values that are not explicitly specified are implicitly initialised with 0, and the compiler will know enough to insert a call to memset.

唯一的区别是这样的文体。选择将取决于您所使用的编码标准,或者您的个人preferences。

The only difference is thus stylistic. The choice will depend on the coding standard you use, or your personal preferences.

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

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