gpt4 book ai didi

c - 如果输入到字符数组中的字符数少于指定的空格数,会发生什么情况

转载 作者:太空狗 更新时间:2023-10-29 15:17:27 25 4
gpt4 key购买 nike

char ch_arry[20] = { S, A, L, L, Y};
printf( "%s", ch_arry[] );

它会用空字符填充数组的末尾吗?

最佳答案

来自C标准(6.7.9初始化)

19 The initialization shall occur in initializer list order, each initializer provided for a particular subobject overriding any previously listed initializer for the same subobject;151) all subobjects that are not initialized explicitly shall be initialized implicitly the same as objects that have static storage duration.

10 If an object that has automatic storage duration is not initialized explicitly, its value is indeterminate. If an object that has static or thread storage duration is not initialized explicitly, then:

— if it has pointer type, it is initialized to a null pointer;

if it has arithmetic type, it is initialized to (positive or unsigned) zero;

— if it is an aggregate, every member is initialized (recursively) according to these rules, and any padding is initialized to zero bits;

所以如果你有这样的声明

char ch_arry[20] = { 'S', 'A', 'L', 'L', 'Y'};

然后数组中所有未显式初始化的元素都将用零隐式初始化。

关于c - 如果输入到字符数组中的字符数少于指定的空格数,会发生什么情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44953860/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com