Why is this array having all remaining values initialized to zero?

C11 6.7.9 Initialization p19 covers this (my emphasis) 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. Section 6.7.9 p10 … Read more

Braces around string literal in char array declaration valid? (e.g. char s[] = {“Hello World”})

It’s allowed because the standard says so: C99 section 6.7.8, ยง14: An array of character type may be initialized by a character string literal, optionally enclosed in braces. Successive characters of the character string literal (including the terminating null character if there is room or if the array is of unknown size) initialize the elements … Read more

Is there a way to not have to initialize arrays twice?

In some cases, you can use std::mem::MaybeUninit: use std::mem::MaybeUninit; fn main() { let mut ys: MaybeUninit<[i32; 1000]> = MaybeUninit::uninit(); } Removing the MaybeUninit wrapper via assume_init is unsafe because accessing uninitialized values is undefined behavior in Rust and the compiler can no longer guarantee that every value of ys will be initialized before it is … Read more