当初始化字符数组,是剩余空间零填充或初始化? [英] When initializing a char array, is the remaining space zero filled or uninitialized?

查看:208
本文介绍了当初始化字符数组,是剩余空间零填充或初始化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于

char foo[1024] = "bar";

这将初始化富遏制'B','A','R',0。在剩余1020个字符初始化为零,或者未初始化?

This will initialize foo to contain 'b','a','r',0 . Is the remaining 1020 characters zero initialized, or uninitialized ?

我觉得上面是一样的`字符富[1024] = {'B','A','R','\\ 0'};并且与骨料的初始化,没有提到任何成员被初始化为零?

I'd think the above is the same as `char foo[1024] = {'b','a','r','\0'} ; and as with initializing of aggregates, any member not mentioned is initialized to zero ?

推荐答案

如果数组/总以某种​​方式初始化,其余未指定的条目被归零,是

If an array/aggregate is initialized somehow[edit: by use of a static initializer], the remaining unspecified entries are zeroed, yes.

这篇关于当初始化字符数组,是剩余空间零填充或初始化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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